This feature is not Baseline because it does not work in some of the most widely-used 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.
A reference to an existing Element that the button controls.
const popover = document.getElementById("mypopover");
const toggleBtn = document.getElementById("toggleBtn");
toggleBtn.commandForElement = popover;
| Specification |
|---|
| HTML> # dom-button-commandforelement> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
commandForElement |
135 | 135 | preview | 120 | preview | 135 | No | 89 | No | No | 135 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement/commandForElement