This feature is not Baseline because it does not work in some of the most widely-used browsers.
The source read-only property of the CommandEvent interface returns an EventTarget representing the control that invoked the given command.
An EventTarget object. Usually an HTMLButtonElement.
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 },
);
| Specification |
|---|
| HTML> # dom-commandevent-source> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
source |
135 | 135 | preview | 120 | preview | 135 | No | 89 | No | No | 135 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CommandEvent/source