I'd like to make a simple text editor to allow people to make the font bold, italicized or underlined. I'm a little confused on how to use the "active" class on twitter bootstrap's buttons to toggle functions such as adding different font styles to words in a textarea.
Here's my HTML:
<span class="btn-group" data-toggle="buttons-checkbox">
<button class="btn btn-bold">Bold</button>
<button class="btn btn-italics">Italics</button>
<button class="btn btn-underline">Underline</button>
</span>
<textarea></textarea>
here's my JS:
$('.btn').click(function(){
if($('.btn-bold').hasClass('active')){
$('.btn-bold').toggle(
function() {
$('textarea').val($('textarea').val()+"<span style='font-weight:bold'>");},
function() {
$('textarea').val($('textarea').val()+"</span>");
}); //toggle
} //if
}); //click
I think i need to have code like this for each font-style: bold, italics, underline I toggle. But as you can see what I have for just making text bold is quite verbose (not to mention doesn't work) so there has to be a better way. Any thoughts would be greatly appreciated.