JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" value="abcd">
<button id="check">check position</button>
<button id="move">move position</button>
JavaScript
$(function () {
$('#check').click(function(e) {
e.preventDefault();
$('input').focus();
console.log($('input')[0].selectionStart);
});
$('#move').click(function(e) {
e.preventDefault();
var press = jQuery.Event("keypress");
press.ctrlKey = false;
press.which = 37;
$('input').focus();
setTimeout(function(){
$('input').trigger(press);
console.log('event triggered!');
}, 1000);
});
});