$(":input:text:eq("+ nxtIdx +")")
this selector returns an array so you can either use [0] indexing or use val() to get the value which will return the first element matches to the selector.
You can use $(":input:text:eq("+ nxtIdx +")")[0]
or $(":input:text:eq("+ nxtIdx +")").val()
$(function() { $('input:text:first').focus(); var $inp = $('input:text'); $inp.bind('keydown', function(e) { var key = e.which; if (key == 13) { e.preventDefault(); var nxtIdx = $inp.index(this) + 1; if ($(":input:text:eq("+ nxtIdx +")").length > 0) { $(":input:text:eq("+ nxtIdx +")").focus(); $(":input:text:eq("+ nxtIdx +")")[0].setSelectionRange(0, $(":input:text:eq("+ nxtIdx +")")[0].value.length) } } });});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><input /><input />