JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" name="message" id="message" value="Lorem ipsum" />
JavaScript
$.fn.setCursorPos = function(position) {
return this.each(function() {
var node = this;
node.focus();
if (node.setSelectionRange) {
node.setSelectionRange(position, position);
} else if (node.createTextRange) {
var textRange = node.createTextRange();
textRange.collapse(true);
textRange.move('character', position);
textRange.select();
}
node.selectionStart = position;
});
};
$('#message').setCursorPos(5);