Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
Since September 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。
selectionchange は選択 API のイベントで、 <input> 要素の中でテキストの選択状態が変化したときに発行されます。 これは、文字単位の選択範囲位が変化した場合も、キャレットが移動したときも含みます。
このイベントはキャンセル不可です。
このイベントは通常 <input> 上にイベントリスナーを追加し、ハンドラー関数内で HTMLInputElement の selectionStart、selectionEnd、selectionDirection の各プロパティを読み取ることで処理します。
また、onselectionchange イベントハンドラーにリスナーを追加し、ハンドラー関数内で Document.getSelection() を使って選択状態を得ることもできます。しかし、これはテキストの選択範囲の変更を取得するのにはあまり便利ではありません。
このイベント名を addEventListener() 等のメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。
一般的な Event です。
以下の例は、 <input> 要素の中にあるテキストの選択状態を取得する方法を示しています。
| Selection API # selectionchange-event |
| Selection API # dom-globaleventhandlers-onselectionchange |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2024年4月11日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.