Document: selectionchange event

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 HTMLInputElement.selectionchange_event for more details.


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

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

onselectionchange = (event) => {};

Event type

A generic Event.


// addEventListener version
document.addEventListener("selectionchange", () => {

// onselectionchange version
document.onselectionchange = () => {


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

Browser compatibility

BCD tables only load in the browser

See also