JSFiddle - React, Tailwind, and code Playground

by Сергей Тарасевич

HTML

<input type="text" value="231231">
<input type="text" value="231232">
<input type="text" value="231233">
<input type="text" value="231234">

JavaScript

$.fn.setCursorPosition = function(pos) {
    'use strict';
     	console.log(pos);
   this.each(function(i, e) {
    	console.log(i);
    	console.log(e);
        if (e.setSelectionRange) {
            e.setSelectionRange(pos, pos);
        } else if (e.createTextRange) {
            var range = e.createTextRange();
            range.collapse(true);
            range.moveEnd('character', pos);
            range.moveStart('character', pos);
            range.select();
        }
    	console.log(range);
    });
    return this;
};

$(document).on( 'focus', 'input', function() {
    $( this ).setCursorPosition($( this ).val().length);

});