HTML | DOM Input FileUpload autofocus Property
The Input FileUpload autofocus property in HTML DOM is used to set or return whether a file upload button should automatically get focus when the page loads, or not.
Syntax:
- Return the autofocus property:
fileuploadObject.autofocus
- Set the autofocus property:
fileuploadObject.autofocus=true|false
Property Values:
- true : The file upload button get focused
- false : The file upload button does not get focused
Return Value:
- It returns the boolean value which represents that upload button focused or when.
Example-1: Return autofocus property.
<!DOCTYPE html> <html> <head> <style> h1 { color: green; } </style> </head> <body> <center> <h1>Geeks for Geeks</h1> <input type="file" id="myFile" autofocus> <p id="demo"> </p> <button onclick="myFunction()"> Click </button> <script> function myFunction() { var x = document.getElementById( "myFile").autofocus; document.getElementById( "demo").innerHTML = x; } </script> </center> </body> </html> |
chevron_right
filter_none
Output:
Before Click:

After Click:

Example-2: Set autofocus property.
<!DOCTYPE html> <html> <head> <style> h1 { color: green; } </style> </head> <body> <center> <h1> Geeks for Geeks </h1> <input type="file" id="myFile"> <p id="demo"> </p> <button onclick="myFunction()"> Click </button> <script> function myFunction() { var x = document.getElementById( "myFile").autofocus = "true"; document.getElementById( "demo").innerHTML = x; } </script> </center> </body> </html> |
chevron_right
filter_none
Output:
Before Click:

After Click:

Supported Browsers:
- Google Chrome
- Mozilla Firefox
- Edge
- Opera
- Safari
Recommended Posts:
- HTML | DOM Input FileUpload name Property
- HTML | DOM Input FileUpload value Property
- HTML | DOM Input FileUpload disabled Property
- HTML | DOM Input FileUpload accept Property
- HTML | DOM Input FileUpload type Property
- HTML | DOM Input FileUpload required Property
- HTML | DOM Input FileUpload form Property
- HTML | DOM Input FileUpload files Property
- HTML | DOM Input FileUpload multiple Property
- HTML | DOM Input URL autofocus Property
- HTML | DOM Input Button autofocus Property
- HTML | DOM Input Password autofocus Property
- HTML | DOM Input Checkbox autofocus Property
- HTML | DOM Input Range autofocus Property
- HTML | DOM Input Time autofocus Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



