Possible Duplicate:
Identify whether the selected text in a web page is bold nor not
I've created a contenteditable div, and this was straightforward enough.
I have as well added a control on top of the div to bold and unbold the text.
Now, I would like to style the button based on the bold status of the text under the cursor - ie: if the text under the cursor is bold, I would like the bold icon to have border 'inset'... and if it's not bold, I would like the bold icon to be without a border.
How can I check the style of the element under the cursor?
Link to the code as it is now: http://jsfiddle.net/aCp7M/
Here you are: http://jsfiddle.net/vvCzD/
Use document.queryCommandValue("Bold")
to check that text at the caret position is bold and so on.
All possible command identifiers are described here.
UPD:
As Tim stated below, a correct method for getting boolean-like properties is queryCommandState
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With