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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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

chevron_right


Output:

Before Clicking On Button :

After Clicking On Button:

Example-2:This Example illustrates how to set the autofocus Property.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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

chevron_right


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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.