I have a div with contenteditable="true" and I want to get the background color of the selected text. It works fine in Chrome but it fails in Firefox by returning "transparent" all the time. Here is now I try to do it. HTML:
<div contenteditable="true" id="selector" style="background-color: rgb(255,255,0);">
Test back<span style="background-color: rgb(255,0,0);">ground</span> color.
</div>
Javascript
$('div#selector').on('mouseup', function (){
alert(document.queryCommandValue('backColor'));
});
Sample: http://jsfiddle.net/4Wk2X/11/
Do you have any idea why this happens?
I managed to get it work by using the parent of the selection and then the CSS background-color property.
See http://jsfiddle.net/4Wk2X/14/