Document: selectionchange イベント

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.

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

このイベントはキャンセル不可で、バブリングしません。

このイベントは selectionchange のイベントリスナーを追加するか、onselectionchange イベントハンドラーを使用して処理することができます。

メモ: このイベントは <input><textarea> 要素のテキスト選択が変更されたときに発行される selectionchange イベントとは異なります。詳しくはHTMLInputElement.selectionchange_eventを参照してください。

構文

このイベント名を addEventListener() などのメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。

js
addEventListener("scrollend", (event) => {});

onscrollend = (event) => {};

イベント型

一般的な Event です。

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

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

仕様書

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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
selectionchange event

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報