CommandEvent: source プロパティ
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
source は CommandEvent インターフェイスの読み取り専用プロパティで、指定されたコマンドを呼び出したコントロールを表す EventTarget を返します。
値
EventTarget オブジェクトです。通常は HTMLButtonElement です。
例
以下の簡単な例では、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 },
);
仕様書
| Specification |
|---|
| HTML> # dom-commandevent-source> |
ブラウザーの互換性
Loading…