HTMLButtonElement: commandForElement property
Baseline
2025
Newly available
Since December 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The commandForElement property of the HTMLButtonElement interface gets and sets the element to control via a button.
It is the JavaScript equivalent of the commandfor HTML attribute.
Value
A reference to an existing Element that the button controls.
Examples
js
const popover = document.getElementById("mypopover");
const toggleBtn = document.getElementById("toggleBtn");
toggleBtn.commandForElement = popover;
Specifications
| Specification |
|---|
| HTML> # dom-button-commandforelement> |