简体   繁体   中英

firefox selectionchange event for textarea?

Listening for selectionchange events in a textarea works in chrome and safari, but not in firefox.

<div>selecting me will detect your selecting!</div>
<textarea>alas, I will not!</textarea>
<div id="f"></div>
document.addEventListener( 'selectionchange', function() {
  document.getElementById('f').innerHTML += '<br>selecting';
});

What event should I be listening for instead?

demo

https://codepen.io/jedierikb/pen/XWXxmZW

While document 'selectionchange' events do not fire in firefox textareas, textareas themselves can listen for 'select' events, which fire the same event types.

https://developer.mozilla.org/en-US/docs/Web/API/Element/select_event

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM