このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

CommandEvent: source プロパティ

Baseline 2025
Newly available

Since ⁨December 2025⁩, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

sourceCommandEvent インターフェイスの読み取り専用プロパティで、指定されたコマンドを呼び出したコントロールを表す 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

ブラウザーの互換性

関連情報