Friday, October 1, 2010

Contenteditable reset text color after foreColor has been used without resetting other styles

Programmer Question

Changing the text color of text in a contenteditable div is easy - simply called document.execCommand("foreColor",false,"#FFF") to change text color to white.



However, I cannot find a way to reset this color back to its default value (or to the value of the parent element). document.execCommand("removeFormat",false,null) works perfectly, except that it will also remove any bold or italic styles, which is not what I want. Simply setting the color to black works, apart from if you have a link in the selection (which should stay the same color).



Is this possible?



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails