← 4.11 Interactive elementsTable of contents4.12 Links →

4.11.5 Commands

A command is the abstraction behind menu items, buttons, and links.

Commands are defined to have the following facets:

Type
The kind of command: "command", meaning it is a normal command; "radio", meaning that triggering the command will, amongst other things, set the Checked State to true (and probably uncheck some other commands); or "checkbox", meaning that triggering the command will, amongst other things, toggle the value of the Checked State.
ID
The name of the command, for referring to the command from the markup or from script. If a command has no ID, it is an anonymous command.
Label
The name of the command as seen by the user.
Hint
A helpful or descriptive string that can be shown to the user.
Icon
An absolute URL identifying a graphical image that represents the action. A command might not have an Icon.
Access Key
A key combination selected by the user agent that triggers the command. A command might not have an Access Key.
Hidden State
Whether the command is hidden or not (basically, whether it should be shown in menus).
Disabled State
Whether the command is relevant and can be triggered or not.
Checked State
Whether the command is checked or not.
Action
The actual effect that triggering the command will have. This could be a scripted event handler, a URL to which to navigate, or a form submission.

These facets are exposed on elements using the command API:

element . commandType

Exposes the Type facet of the command.

element . id

Exposes the ID facet of the command.

element . label

Exposes the Label facet of the command.

element . title

Exposes the Hint facet of the command.

element . icon

Exposes the Icon facet of the command.

element . accessKeyLabel

Exposes the Access Key facet of the command.

element . hidden

Exposes the state of the element's hidden attribute, which is generally equivalent to the Hidden State facet of the command. For label and legend elements (used in conjunction with the accesskey attribute), the Hidden State facet is derived from another element (the one that the assigned access key will trigger), and cannot be directly accessed from the element.

element . disabled

Exposes the Disabled State facet of the command.

element . checked

Exposes the Checked State facet of the command.

element . click()

Triggers the Action of the command.


document . commands

Returns an HTMLCollection of the elements in the Document that define commands and have IDs.


User agents may expose the commands whose Hidden State facet is false (visible), e.g. in the user agent's menu bar. User agents are encouraged to do this especially for commands that have Access Keys, as a way to advertise those keys to the user.