Reputation: 2445
I am trying to setup some bold, italic and underline buttons for my textarea, I am using this code to make the switch from normal to bold/italic/underline.
document.execCommand("bold", false, "");
It works perfect in Chrome, but in Firefox and ie it doesn't change the text to bold or anything and I cannot work out why?
Here is the full code:
<input name="new_shout_bold" type="button" class="new_shout_text_option" id="new_shout_bold" onclick='document.execCommand("bold", false, "");' value="B" alt="B" />
<input name="new_shout_italic" type="button" class="new_shout_text_option" onclick='document.execCommand("italic", false, "");' value="I" alt="I" style="font-style: italic;"/>
<input name="new_shout_underline" type="button" class="new_shout_text_option" onclick='document.execCommand("underline", false, "");' value="U" alt="U" style="text-decoration: underline;" />
Here is the textarea:
<div id="dash_new_shout_textarea" name="dash_new_shout_textarea" class="dash_new_shout_textarea" contenteditable="true"></div>
Any Ideas?
Upvotes: 2
Views: 4862
Reputation: 3551
I know this won't help too much, but this code works perfectly fine in Chrome and Firefox
http://jsbin.com/iluXOGe/2/edit
Upvotes: 0
Reputation: 324477
Make the the buttons unselectable in IE by adding unselectable="on"
to the HTML tag.
Upvotes: 2