For mobile devices, when you swipe the spacebar in an input field, the cursor changes position. What JS event is used to capture that event?
For mobile devices, when you swipe the spacebar in an input field, the cursor changes position. What JS event is used to capture that event?
Use selectionchange to detect changes of the caret/cursor:
document.onselectionchange = () => {
var sel = document.getSelection()
info.innerHTML =
'anchorOffset: ' + sel.anchorOffset + '<br>' +
'focusOffset: ' + sel.focusOffset + '<br>'
}
<p contenteditable>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</p>
<div id="info">info</div>