jquery move cursor to position code example
Example: jquery get cursor position
Use selectionStart, it is compatible with all major browsers.
document.getElementById('foobar').addEventListener('keyup', e => {
console.log('Caret at: ', e.target.selectionStart)
})
<input id="foobar" />