Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 event for `onselectionchange`

Is there a standard cross-browser HTML5 event which corresponds to IE legacy onselectionchange (so it is fired when the current selection changes)?

EDITED, I'm looking to track Selection object changes.

like image 445
avo Avatar asked Sep 12 '25 00:09

avo


1 Answers

Never too late :

// IE
myEditableElement.onselectionchange = onSelectionChange;
// work on chrome, untested on firefox
myEditableElement.addEventListener('focus', function (event) {
  document.addEventListener('selectionchange', onSelectionChange);
});
myEditableElement.addEventListener('focusout', function (event) {
  document.removeEventListener('selectionchange', onSelectionChange);
});

// Event
function onSelectionChange (event) {
  // todo
}
like image 115
Scurra Magna Avatar answered Sep 13 '25 15:09

Scurra Magna