MDN self-hosted library · e01.org

CommandEvent: command property

Invoker Commands API

Open notebook · 1 cells web-api-instance-property upstream source

Invoker Commands API

The command read-only property of the CommandEvent interface returns a string containing the value of the command property at the time the event was dispatched.

Value

A string.

Examples

In the following simple example we've set up an event listener to listen for the "show-modal" command:

document.body.addEventListener(
  "command",
  (event) => {
    const theAction = event.command;

    if (theAction === "show-modal") {
      console.log("Showing modal dialog");
    }
  },
  { capture: true },
);

Specifications

Browser compatibility

See also

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