I am trying to get the position of the text cursor immediately after one clicks down the mouse to reposition it. The issue is that selectionStart and selectionEnd do not return the most current position of the cursor, since the "new" position doesn't get stored until the click is released. The code snippet shows this problem when you try to reposition the caret with the mouse.
This is strange because I can technically type at the "new" position as soon as the mouse is clicked down, but selectionStart still returns the old position. If the cursor position can clearly change without having to release the click, then how do you access the new position without having to wait for the mouseup?
(this also seems to be a problem for tracking cursor position after keydowns)
const input = document.getElementById('myInput');
input.addEventListener('mousedown', showposition); // click
function showposition() {
document.getElementById("output").innerHTML += " " + input.selectionStart;
}
<input id="myInput">
<p id="output"></p>