Posts Tagged ‘focus() after last character in textbox IE’

h1

JQuery focus() after last character in textbox not woking in IE – Solution

May 7, 2015

In other browsers $(‘#TextBox’).focus() this code will work. for IE we need to do something special!!! in code

Code :

Create a function:

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

also we need to use setTimeout.

setTimeout(function() {
$(‘#TextBox’).focus();$(‘#TextBox’).setCursorToTextEnd();
}, 100);

Source 1
Source 2

Advertisements