Open In App

HTML | DOM Button autofocus Property

Improve
Improve
Like Article
Like
Save
Share
Report

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.




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

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


    Last Updated : 19 Feb, 2019
    Like Article
    Save Article
    Previous
    Next
    Share your thoughts in the comments
Similar Reads