Get to know MDN better
Since December 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The Invoker Commands API provides a way to declaratively assign behaviors to buttons, allowing control of interactive elements when the button is enacted (clicked or invoked via a keypress, such as the spacebar or return key).
A common pattern on the web is to have <button> elements control various aspects of the page, such as opening and closing popovers or <dialog> elements, formatting text, and more.
Historically creating these kinds of controls has required JavaScript event listeners added to the button which can then call the APIs on the element they control. The commandForElement and command properties provide a way to do this declaratively for a limited set of actions. This can be advantageous for built-in commands as the user does not have to wait for JavaScript to download and execute to make these buttons interactive.
Turns a <button> element into a command invoker, controlling the given interactive element; takes the ID of the element to control as its value.
commandSpecifies the action to be performed on an element being controlled by a control <button>, specified via the commandfor attribute.
Represents an event notifying the user that a command has been issued. It is the event object for the command event. The event fires on element referenced by commandForElement.
Gets and sets the element being controlled by the button. The JavaScript equivalent of the commandfor HTML attribute.
HTMLButtonElement.commandGets and sets the action to be performed on the element being controlled by the button. Reflects the value of the command HTML attribute.
Fired on the element referenced by the button.
| HTML # commandevent |
| HTML # dom-button-commandforelement |
| HTML # dom-button-command |
Enable JavaScript to view this browser compatibility table.
Enable JavaScript to view this browser compatibility table.
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jan 19, 2026 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.