March 26 2017

Jquery set focus on last character in input text box

Tagged Under :

javascript
Normally using Jquery or Javascript to set focus on input box it will point to beginning of the text box. But if you want it point to last character in input text box. you may need write a Jquery class to do.

Below is the Jquery function:
(function($){
    $.fn.focusTextToEnd = function(){
        this.focus();
        var $thisVal = this.val();
        this.val('').val($thisVal);
        return this;
    }
}(jQuery));

You may easy to use the function like below
$("#input").focusTextToEnd();