HTML | DOM Input Button autofocus Property
The DOM Input Button autofocus Property in HTML DOM is used to set or return whether the Input Button field should get automatically get focus or not when the page loads. This Property is used to reflect the HTML autofocus attribute.
Syntax:
- It returns the autofocus property.
buttonObject.autofocus
- It is use to set the autofocus property.
buttonObject.autofocus = true|false
Property Values:
- true: It specify that the Button field get focus.
- false: It specify that the Button field does not get focus. It has a default value.
Return Value: It returns a Boolean value which represents that the Button field get focus or not when the page loads.
Example-1: This Example illustrates how to return the autofocus Property.
<!DOCTYPE html> <html> <head> <style> h1 { color: green; } </style> </head> <body style="text-align:center;"> <h1>GeeksForGeeks</h1> <h2> DOM Input Button autofocus Property </h2> <form id="myGeeks"> <!-- Assigning button id --> <input type="button" id="GFG" onclick="myGeeks()" name="Geek_button" value="Submit" autofocus> </form> <p id="sudo" style="color:green;font-size:25px;"></p> <script> function myGeeks() { // accessing 'button' id. var g = document.getElementById("GFG").autofocus; document.getElementById("sudo").innerHTML = g; } </script> </body> </html> |
Output:
Before Clicking On Button :

After Clicking On Button:

Example-2:This Example illustrates how to set the autofocus Property.
<!DOCTYPE html> <html> <head> <style> h1 { color: green; } </style> </head> <body style="text-align:center;"> <h1>GeeksForGeeks</h1> <h2> DOM Input Button autofocus Property </h2> <form id="myGeeks"> <!-- Assigning button id --> <input type="button" id="GFG" onclick="myGeeks()" name="Geek_button" value="Submit" autofocus> </form> <p id="sudo" style="color:green;font-size:25px;"></p> <script> function myGeeks() { // accessing 'button' id. var g = document.getElementById("GFG").autofocus = false; document.getElementById("sudo").innerHTML = g; } </script> </body> </html> |
Output :
Before Clicking On Button:

After Clicking On button:

Supported Browsers: The browser supported by DOM input Button autofocus property listed below:
- Google Chrome
- Internet Explorer 10.0 +
- Firefox
- Opera
- Safar
Recommended Posts:
- HTML | DOM Button autofocus Property
- HTML | DOM Input URL autofocus Property
- HTML | DOM Input Checkbox autofocus Property
- HTML | DOM Input Submit autofocus Property
- HTML | DOM Input Datetime autofocus Property
- HTML | DOM Input Search autofocus Property
- HTML | DOM Input Email autofocus Property
- HTML | DOM Input Month autofocus Property
- HTML | DOM Input Number autofocus Property
- HTML | DOM Input Range autofocus Property
- HTML | DOM Input Text autofocus Property
- HTML | DOM Input Time autofocus Property
- HTML | DOM Input Week autofocus Property
- HTML | DOM Input Reset autofocus Property
- HTML | DOM Input FileUpload 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.



