Focus element in ThickBox March 24, 2009

I faced with a problem focusing element in thickbox popup. I open login form using thickbox and want to take a focus on the first element of the form. Though the following code does look to be working:
$(document).ready(function() {
$("input[name='username']").focus();
});

But there is a little trick. If you make a small 100ms delay in focus() call it works:
$(document).ready(function() {
setTimeout("$(\"input[name='username']\").focus();", 100);
});

 
7 Comments
derp April 1st, 2010

thanks!

 
Ismael July 29th, 2010

Thank you!!!! I was getting really upset because I couldn’t focus a simple textbox, but I thought… “could it be thickbox?” and I found your answer later, thank you! :)

 
Pozzebon October 27th, 2010

Thank you. This solved a big problem!

 
chrlvclaudiu November 1st, 2010

thank you. your method is working.

 
wellington February 15th, 2011

thanks, I’M FROM BRAZIL AND your method is working.

 
Andre March 8th, 2012

Hello klalex, I’m a beginner in jQuery and I’m having problems with focusing a text field. Just a question… the code above must be put in what event?

 
Rajeev August 4th, 2012

Thank you

 
Leave a Reply