Sometimes before I faced a issue the jQuery focus not working in Chrome and in Mozilla It was working fine. I have google the issue and came up with a solution. Same solution I am explaining here so that It can be useful for developers.
Issue:
I have an input box and after submitting the data input in this element and trying to focus on it eg
$('input#fellowtuts').focus()
It doesn’t work, no error is thrown but the element isn’t focused.
It seems bug in chrome. Sometimes it is too fast to execute events properly. So I have got the solution of this issue by doing some delay using setTimeout() as follows :
setTimeout(function(){
$("input#fellowtuts").focus();},100);
and this code works fine, using setTimeout()
with a minimal delay. It will slow down Chrome and make it work.
I hope this article would be helpful and if you have any problem facing in respect of jQuery or JavaScript, you can write us on our site http://fellowtuts.com. We will try our best to provide you a solution as soon as possible.
Hi,
i need your help on the following defect
i tried using both focus() and setTimeout method even then i m not able to focus a page ..Its working fine in IE but not on chrome and firefox