I am currently working on a DIY WYSIWYG text editor using javascript.
One of the button is to highlight the selected text into yellow color, with the code (in the function):
rtf.document.execCommand('backColor', false, "#FFFF00");
It works fine, but I want that, if the button is clicked again, any highlighted area will be "unhighlighted", which I think of something like this:
var current_text = window.frames['rtf'].document.body.innerHTML;
rtf.document.execCommand('backColor', false, "#FFFF00");
if (window.frames['rtf'].document.body.innerHTML == current_text) {
rtf.document.execCommand('backColor', false, "");
alert('testing');
}
When I selected a highlighted area and press the button, the "testing" alert did show up, but the selected text was not "unhighlighted". And I could search for ways that execCommand('backColor') can "unhighlight" a piece of text.
Anyone can help?