Document: selectionchange event
The selectionchange
event of the Selection API is fired when the current Selection
of a Document
is changed.
Bubbles | No |
---|---|
Cancelable | No |
Interface | Event |
Event handler property | onselectionchange |
The event can be handled by adding an event listener for selectionchange
or using the global 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 GlobalEventHandlers.onselectionchange
for more information.
Examples
// addEventListener version
document.addEventListener('selectionchange', () => {
console.log(document.getSelection());
});
// onselectionchange version
document.onselectionchange = () => {
console.log(document.getSelection());
};
Specifications
Specification |
---|
Selection API # selectionchange-event |
Browser compatibility
BCD tables only load in the browser