Back to Content

HTMLButtonElement: commandForElement property

files/en-us/web/api/htmlbuttonelement/commandforelement/index.md

latest804 B
Original Source

{{APIRef("Invoker Commands API")}}

The commandForElement property of the {{domxref("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 {{domxref("Element")}} that the button controls.

Examples

js
const popover = document.getElementById("mypopover");
const toggleBtn = document.getElementById("toggleBtn");

toggleBtn.commandForElement = popover;

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{domxref("Invoker Commands API", "Invoker Commands API", "", "nocode")}}
  • {{domxref("HTMLButtonElement.command")}}
  • {{domxref("CommandEvent")}}