GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • MDN
  • HTML: Markup language
  • Elements
  • Global attributes
  • Attributes
  • See all…
  • Responsive images
  • HTML cheatsheet
  • Date & time formats
  • See all…
  • SVG
  • MathML
  • XML
  • CSS: Styling language

This view

  • Original page
  • New address

GeezerVison is showing developer.mozilla.org — HTMLElement: command event - Web APIs | MDN

HTMLElement: command event

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.

  • See full compatibility
  • Learn more

The command event of the HTMLElement interface fires on an element that is controlled via a button with valid commandForElement and command values, whenever the button is interacted with (e.g., it is clicked).

Syntax

Use the event name in addEventListener():

js
addEventListener("command", (event) => { })

Alternatively, assign to the event handler property of the interface:

js
oncommand = (event) => { }

Event type

A CommandEvent. Inherits from Event.

Examples

Basic example

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

// …

popover.addEventListener("command", (event) => {
  if (event.command === "show-popover") {
    console.log("Popover is about to be shown");
  }
});

Event dispatch and cancellation

It is worth pointing out that command events fire on the element being invoked. If the button is clicked, it will first dispatch a click event which, if canceled, then the command event will not fire and the default behavior will not be run. In addition to canceling the click event on the button, it is also possible to cancel the command event.

For example:

js
button.addEventListener("click", (event) => {
  event.preventDefault(); // the `command` event will never fire
});
js
element.addEventListener("command", (event) => {
  event.preventDefault(); // the `command` event fires but the default behavior is canceled
});

Specifications

Specification
HTML
# event-command

Browser compatibility

See also

  • Invoker Commands API
  • HTMLButtonElement.command
  • HTMLButtonElement.commandForElement

Help improve MDN

Learn how to contribute

This page was last modified on Oct 26, 2026 by MDN contributors.

View this page on GitHub • Report a problem with this content
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.