HTML5 contentEditable check if format is applied with execCommand?

Highlight selected text in bold:

document.execCommand('bold', null, null); 

When the user selects this piece of text (or part of it) again, how can you know that it was highlighted in bold?

Bold is just an example. commandName can be underline , heading , createLink , ...

+6
source share
2 answers
 document.queryCommandState 

Determines whether this command was executed in the current selection.

Source: http://blog.whatwg.org/the-road-to-html-5-contenteditable#how

Apparently I was not looking good enough.

+11
source

You will know it in bold because it has been wrapped with <b></b> tags. (or something that the user agent uses for bold text)

0
source

Source: https://habr.com/ru/post/892916/


All Articles