Firefox Tomorrow

web api instance property

CommandEvent: source property

View on MDN ↗

The source read-only property of the CommandEvent interface returns an EventTarget representing the control that invoked the given command.

Value

An EventTarget object. Usually an HTMLButtonElement.

Examples

In the following simple example we’ve set up an event listener to add a temporary class to the button element upon a CommandEvent:

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

    theButton.classList.add("just-pressed");

    setTimeout(() => {
      theButton.classList.remove("just-pressed");
    }, 1000);
  },
  { capture: true },
);

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also