jQuery focus() on Bootstrap input field not working

javascript, jquery, twitter-bootstrap

Solution

You probably need to wait until page has loaded. Try something like:

$(document).ready(function () {$('#searchbox').focus(); });

Problem

I want a search input field to automatically get focus on page load. So I tried the following approach: ``` (function () { $('#searchbox').focus(); }) ``` This however does nothing at all. I thought it might conflict with some other code I have, so I did a simple test at a Bootstrap example page http://twitter.github.com/bootstrap/examples/hero.html. In the Chrome console, I typed `$('input:first').focus();` and this gave me `<input class="span2" type="text" placeholder="Email">` as return value, but it didn't focus on the e-mail field too. What am I doing wrong to simply focus on a certain input field when a page loaded?

Original source