Document: selectionchange event

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.

The selectionchange event of the Selection API is fired when the current Selection of a Document is changed.

This event is not cancelable and does not bubble.

The event can be handled by adding an event listener for selectionchange or using the onselectionchange event handler.

Note: This event is not quite the same as the selectionchange events fired when the text selection in an <input> or <textarea> element is changed. See the selectionchange event of HTMLInputElement for more details.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

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

onselectionchange = (event) => {};

Event type

A generic Event.

Examples

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

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

Specifications

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

Browser compatibility

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

See also