CommandEvent: source property

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

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:

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

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

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

Specifications

No specification found

No specification data found for api.CommandEvent.source.
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

BCD tables only load in the browser

See also