command

The command event is executed when an element is activated.

How it is activated varies for each element and in many cases, there are several ways to activate an element. For example, a button can be activated by clicking on it with the mouse or by pressing SPACE while it has the focus. Menus can be activated by selecting them with the mouse or by pressing a shortcut key. Command elements can be activated by any of their observing elements being activated. The command event should always be used instead of the click event because it will be called in all of the needed cases.

General info

Specification
XUL
Interface
XULCommandEvent
Bubbles
Yes
Cancelable
Yes
Target
element
Default Action
None

Properties

Property Type Description
target Read only EventTarget The event target (the topmost target in the DOM tree).
type Read only DOMString The type of event.
bubbles Read only Boolean Whether the event normally bubbles or not
cancelable Read only Boolean Whether the event is cancellable or not?
view Read only WindowProxy document.defaultView (window of the document)
detail Read only long (float) Unused; always zero.
ctrlKey Read only boolean true if the control key was down when the event was fired. false otherwise.
shiftKey Read only boolean true if the shift key was down when the event was fired. false otherwise.
altKey Read only boolean true if the alt key was down when the event was fired. false otherwise.
metaKey Read only boolean true if the meta key was down when the event was fired. false otherwise.

Example

menuitem.oncommand = function() {
  console.log("the menu item has been activated");
};

Document Tags and Contributors

 Contributors to this page: teoli, Sheppy, ethertank, Neil, louisremi
 Last updated by: teoli,