Thursday, September 6, 2012

JQuery - set cursor/focus after last character in textbox

1. Create a function:


(function($){
    $.fn.setCursorToTextEnd = function() {
        $initialVal = this.val();
        this.val($initialVal + ' ');
        this.val($initialVal);
    };
})(jQuery);

2. Call the function after the normal JQuery focus function:

$('#my_text_box').focus();
$('# my_text_box').setCursorToTextEnd();





Cheers!

No comments:

Post a Comment