JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" name="username" DIR="RTL" />
JavaScript
function setCursor(node,pos){
var node = (typeof node == "string" || node instanceof String) ? document.getElementById(node) : node;
if(!node){
return false;
}else if(node.createTextRange){
var textRange = node.createTextRange();
textRange.collapse(true);
textRange.moveEnd(pos);
textRange.moveStart(pos);
textRange.select();
return true;
}else if(node.setSelectionRange){
node.setSelectionRange(pos,pos);
return true;
}
return false;
}
function zeroCursor(_txt){
setCursor(_txt, 0);
}
$('input').keypress(function() {
zeroCursor(this);
});