Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML | DOM Input Button autofocus Property

  • Difficulty Level : Basic
  • Last Updated : 23 Oct, 2019

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:

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

  • 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.




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

Output:

Before Clicking On Button :

After Clicking On Button:

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




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

Output :
Before Clicking On Button:

After Clicking On button:

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

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



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!