The Button autofocus property in HTML DOM is used to set or return whether the button should get focus when the page loads. This property is used to reflect the HTML autofocus attribute.
Syntax:
- It is used to return the autofocus property.
buttonObject.autofocus
- It is used to set the autofocus property.
buttonObject.autofocus = true|false
- true: It defines the button element get focused.
- false: It is the default value. It defines the Button Element does not get focus.
- Google Chrome
- Internet Explorer 10.0
- Firefox
- Opera
- Safari
- HTML | DOM Input Button autofocus Property
- HTML | <button> autofocus Attribute
- HTML | DOM Textarea autofocus Property
- HTML | DOM Input Time autofocus Property
- HTML | DOM Input Date autofocus Property
- HTML | DOM Input Datetime autofocus Property
- HTML | DOM Input Checkbox autofocus Property
- HTML | DOM Input Email autofocus Property
- HTML | DOM Input Password autofocus Property
- HTML | DOM Input Text autofocus Property
- HTML | DOM Input Submit autofocus Property
- HTML | DOM Input Number autofocus Property
- HTML | DOM Input Reset autofocus Property
- HTML | DOM Input Search autofocus Property
- HTML | DOM Input Range autofocus Property
- HTML | DOM Input Week autofocus Property
- HTML | DOM Input Month autofocus Property
- HTML | DOM Input URL autofocus Property
- HTML | DOM Input Radio autofocus Property
- HTML | DOM Input FileUpload autofocus Property
Property Values:
Return Value: It returns a boolean value which represents the Button element get autofocus otherwise return False.
Example: This example returns the button autofocus value.
<!DOCTYPE html> <html> <head> <title> HTML DOM button autofocus Property </title> </head> <body style="text-align:center"> <h1 style="color: green;"> GeeksforGeeks </h1> <h2> HTML DOM button autofocus Property </h2> <!-- Assign id to the Button. --> <button id="GFG" autofocus> Submit </button> <br><br> <p> Click on "button" Button to return button autofocus Property. </p> <button onclick="Geeks()"> button </button> <p id="sudo"></p> <!-- Script to return button autofocus value --> <script> function Geeks() { // Return Boolean value to represent Button. var x = document.getElementById("GFG").autofocus; document.getElementById("sudo").innerHTML = x; } </script> </body> </html> |
Output:
Before Click on the Button:

After Click on the Button:

Supported Browsers: The browser supported by DOM Button autofocus property are listed below:
Recommended Posts:
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.


