Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 contentEditable check if format is applied with execCommand?

Making the selected text bold:

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

When the user selects that piece of text again (or a part of it), how can you know that it has been made bold?

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

like image 956
DADU Avatar asked Jul 16 '11 23:07

DADU


People also ask

Why is execCommand deprecated?

execCommand() is completely dead because some parts of it still work fine. Unfortunately the primary issue for me was that browsers use a lot of different code to generate those styles which are not recognized by screen readers used by those who are blind or nearly so.

What is execCommand?

HTML DOM Document execCommand() The applets property returns an empty HTMLCollection in all new browsers. The <applet> element is not supported in HTML5.


1 Answers

document.queryCommandState

Determines whether the given command has been executed on the current selection.

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

Apparently I didn't search well enough.

like image 136
DADU Avatar answered Oct 27 '22 20:10

DADU