HTMLButtonElement: commandForElement property

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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

No specification found

No specification data found for api.HTMLButtonElement.commandForElement.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
commandForElement
Experimental

Legend

Tip: you can click/tap on a cell for more information.

No support
No support
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.

See also