Open In App
Related Articles

HTML | DOM Button autofocus Property

Like Article
Save Article
Report issue
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.
  • 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 DOM button autofocus Property 
    <body style="text-align:center"
        <h1 style="color: green;"
            HTML DOM button autofocus Property
        <!-- Assign id to the Button. -->
        <button id="GFG" autofocus>
            Click on "button" Button to return
            button autofocus Property.
        <button onclick="Geeks()">
        <p id="sudo"></p
        <!-- Script to return button autofocus value -->
            function Geeks() { 
                // Return Boolean value to represent Button. 
                var x = document.getElementById("GFG").autofocus; 
                document.getElementById("sudo").innerHTML = x; 
    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
    Share your thoughts in the comments
Similar Reads