2

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?

dork
  • 4,396
  • 2
  • 28
  • 56

1 Answers1

0

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>

https://jsfiddle.net/xz1upsk8