This is a snapshot of an early working draft and has therefore been superseded by the HTML standard.
This document will not be further updated.
execCommand(commandId, doShowUI, value) method on the
HTMLDocument interface allows scripts to
perform actions on the current selection or at the current caret position.
Generally, these commands would be used to implement editor UI, for
example having a "delete" button on a toolbar.
There are three variants to this method, with one, two, and three arguments respectively. The doShowUI and value parameters, even if specified, are ignored unless otherwise stated.
In this specification, in fact, the doShowUI parameter is always ignored, regardless of its value. It is included for historical reasons only.
When any of these methods are invoked, user agents must act as described in the list below.
For actions marked "editing hosts only", if the selection is not entirely within an editing host, of if there is no selection and the caret is not inside an editing host, then the user agent must do nothing.
The user agent must change the selection so that nothing is selected.
We need some sort of way in which the user can make a selection without risk of script clobbering it.
supelement (or unwrapped, or, if there is no selection, have that semantic inserted or removed — the exact behaviour is UA-defined).
subelement (or, again, unwrapped, or have that semantic inserted or removed, as defined by the UA).
Editing hosts only. This command changes the semantics of the blocks containing the selection.
If there is no selection, then, where in the description below refers to the selection, the user agent must act as if the selection was an empty range at the caret position.
If the value parameter is not specified or has a value other than one of the following literal strings:
...then the user agent must do nothing.
Otherwise, the user agent must, for every position in the selection,
take the furthest block-level element ancestor of that position that
contains only inline-level content and is
not being used as a structured inline-level element, and, if that element is a
descendant of the editing host, rename it (as if the
Element.renameNode() method had been used) according to
the value, by stripping the leading
< character and the trailing
and using the rest as the new tag name, using the HTML namespace.
vendorID-customCommandIDso as to prevent clashes between extensions from different vendors and future additions to this specification.