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?
Asked
Active
Viewed 112 times
2
-
Have you tried anything? You are looking for something like this? https://stackoverflow.com/questions/19755633/detect-when-cursor-position-inside-input-change-in-jquery – joseluismurillorios Oct 15 '19 at 03:03
-
Tried mousedown, mousemove, etc. Can't seem to find the specific event in MDN's event reference. – dork Oct 15 '19 at 03:27
-
Did you found a solution? – Friedrich -- Слава Україні Oct 09 '21 at 01:38
1 Answers
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>

Friedrich -- Слава Україні
- 2,901
- 1
- 21
- 40