HTML and CSS Reference
In-Depth Information
3.2.2. Providing rich-text editing controls with execCommand
As you've already seen, the contenteditable attribute and designMode property
allow developers to make any HTML element editable by the user. But up until now, all
users have been able to do is type and edit text, which is hardly exciting; they've been able
to do that with HTML form elements for ages! It'd be much more impressive if users could
format the text using rich-text editing controls, as they would in a word processing applic-
ation. That's where the Editing API method execCommand comes in.
Editing API
4.0
3.5
5.5
9.0
3.1
execCommand: formatting and editing elements via code
Invoking the execCommand method of an editable element applies a selected formatting
command to the current selection or at the current caret position. This includes basic
formatting like italicizing or bolding text and block changes like creating a bullet list or
changing the alignment of a selection. ExecCommand can also be used to create hyper-
links and insert images. Basic editing commands like copy, cut, and paste can also be used
by execCommand if the browser implements these features. Although the HTML5 stand-
ard specifies these editing commands, it doesn't require the browser to support them. For a
full list of commands standardized in HTML5, see appendix B .
To initiate a formatting or editing action, you must pass one to three arguments to ex-
ecCommand :
• The first argument, command , is a string. command contains the name of the edit-
ing or formatting action.
Search WWH ::




Custom Search