How to make autofocus input for IE browsers?

I want to be able to do my input on autofocus, but when I put it this way:

<input type="text" autofocus="focus"> 

he does not work?

Why is this?

+4
source share
4 answers

autofocus attribute is not supported by IE, so you need to use Javascript. If you use jquery, you can emulate it:

 <input type="text" autofocus="focus"> <script> $(function() {$('[autofocus]').focus()}); </script> 

When IE catches up and adds full autofocus support, you can remove the script from your web page.

+12
source

You can use JavaScript, it will solve your problem: copy this into your HTML tag:

<body OnLoad="document.nameOfForm.nameOfField.focus();">

+5
source

This is not a way to do this.

You should set focus on document.ready with jquery.

See here: http://jsfiddle.net/m77QP/

+1
source

document.getELementById("inputidtag").focus

use this in the script area inside the document ( body or head ) and it will be launched at startup, you can put it at the end of the document (or at least after the object) so that when it starts, it will find it and not will throw an error about how it can not be found. This will focus on the element with id inputidtag .

0
source

Source: https://habr.com/ru/post/1383679/


All Articles