HTML | DOM Button autofocus Property

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
  • Property Values:



    • true: It defines the button element get focused.
    • false: It is the default value. It defines the Button Element does not get focus.

    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.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:
    Before Click on the Button:

    After Click on the Button:

    Supported Browsers: The browser supported by DOM Button autofocus property are listed below:

    • Google Chrome
    • Internet Explorer 10.0
    • Firefox
    • Opera
    • Safari


    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.