Reputation: 573
How can I focus an text input when it is visible which is probably before the whole DOM is ready? I only have to possibility to run a script before the DOM started loading. The reason I want to do this is that the user wants to start typing until the input is visible and loading the DOM takes a while.
I would like to do it with jQuery.
Greetings!
Upvotes: 0
Views: 105
Reputation: 2907
try something like this:
<input id="username" type="text" name="username"/>
<script>
$("#username").focus();
</script>
after declaring DOM in html write your scripts
supported in major Browsers
Upvotes: 1
Reputation: 944429
No need to involve JavaScript. Just use the autofocus attribute.
<input name="foo" autofocus>
Upvotes: 2