Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if the text under the cursor in a contenteditable div is "bold" [duplicate]

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/

like image 545
Alterlife Avatar asked Oct 04 '12 19:10

Alterlife


1 Answers

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.

like image 147
Igor Shastin Avatar answered Oct 21 '22 11:10

Igor Shastin