JSFiddle - React, Tailwind, and code Playground
by anoop26667
HTML
<input type="text" id="input_tag" value="hello beautiful world" />
JavaScript
(function() {
if (!HTMLInputElement.prototype.setSelectionRange) {
HTMLInputElement.prototype.setSelectionRange = function(start, end) {
if (this.createTextRange) {
var range = this.createTextRange();
this.collapse(true);
this.moveEnd('character', start);
this.moveStart('character', end);
this.select();
}
}
}
})();
document.getElementById("input_tag").setSelectionRange(6, 15);