How to focus on a form input text field on page load using jQuery?

Viewed 474673

This is probably very simple, but could somebody tell me how to get the cursor blinking on a text box on page load?

12 Answers

The line $('#myTextBox').focus() alone won't put the cursor in the text box, instead use:

$('#myTextBox:text:visible:first').focus();

$("#search").focus();

You can also use HTML5 element <autofocus>

Related