My goal is to focus an input field after the page is loaded using jQuery. So I tried like in this example:
HTML:
<form>
<input type="text" tabindex="1"><br>
<input type="text" tabindex="2"><br>
<input type="text" tabindex="3"><br>
<input type="text" tabindex="4"><br>
</form>
JavaScript:
$(function () {
$("*[tabindex='3']").focus();
});
But this does not work (tested in FireFox 24.0), although this way is suggested in several other questions here on StackOverflow.
Feel free to experiment with this LIVE DEMO (Sometimes you need to click run after the first pageload).
EDIT:
Changed the example to focus on the third element as the first is focused by default. So please respect, that if your solution works with the first element it might not work with another one!
Example doesn't work on FF 24.0/Win 7 & IE 10/Win 7
EDIT 2:
As ghusse noted the example works outside the fiddle context: DEMO So the question is; what can cause the .focus() function to not work?