so there's this: https://stackoverflow.com/a/48150864/1173856 but it doesn't work in Firefox or Chrome when the input type is a number. In those cases selectionStart
and selectionEnd
are both null.
document.getElementById('foobar').addEventListener('keyup', e => {
console.log('Caret at: ', e.target.selectionStart)
})
<input id="foobar" type="number" />