| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement/commandForElement | [Back] [Original] |
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 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 |
This page was last modified on Apr 14, 2025 by MDN contributors.
HTMLButtonElementYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |