Document: selectionchange イベント

selectionchange イベントは Selection API の一部で、文書における現在のテキストの選択が変更された際に発生します。

バブリング なし
キャンセル 不可
インターフェイス Event
イベントハンドラープロパティ onselectionchange

js
// addEventListener version
document.addEventListener("selectionchange", () => {
  console.log(document.getSelection());
});

// onselectionchange version
document.onselectionchange = () => {
  console.log(document.getSelection());
};

仕様書

Specification
Selection API
# selectionchange-event
Selection API
# dom-globaleventhandlers-onselectionchange

ブラウザーの互換性

BCD tables only load in the browser

関連情報