Get to know MDN better
Since September 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The selectionchange event of the Selection API is fired when the text selection within an <input> element is changed. This includes both changes in the selected range of characters, or if the caret moves.
This event is not cancelable.
The event is usually processed by adding an event listener on the <input>, and in the handler function read by the HTMLInputElement selectionStart, selectionEnd and selectionDirection properties.
It is also possible to add a listener on the onselectionchange event handler, and within the handler function use Document.getSelection() to get the Selection. However this is not very useful for getting changes to text selections.
Use the event name in methods like addEventListener(), or set an event handler property.
A generic Event.
The example below shows how to get the text selected in an <input> element.
| Selection API # selectionchange-event |
| Selection API # dom-globaleventhandlers-onselectionchange |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Sep 25, 2025 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.