JSFiddle - React, Tailwind, and code Playground

by Nikolay Alipiev

HTML

<input id="inp" value="QWERTY_YTREWQ"/>

CSS

#inp { width: 60px; }

JavaScript

var input = document.getElementById("inp");

input.focus();
input.setSelectionRange(9,9);
// input.focus() - this is how it works in Chrome
//input.setSelectionRange(0,1);
//input.setSelectionRange(1,1);

// Try typing a letter in the input
input.addEventListener("keypress", function(e) { 
	value = this.value;
  value = value.slice(0, value.length) + String.fromCharCode(e.charCode).toUpperCase();
  this.value = value;
  this.setSelectionRange(value.length,value.length);
  e.preventDefault();
});