Document: selectionchange イベント
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 |
ブラウザーの互換性
BCD tables only load in the browser