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!
No need to involve JavaScript. Just use the autofocus attribute .
<input name="foo" autofocus>
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.