Open In App

HTML DOM Input Tel autofocus Property

Improve
Improve
Like Article
Like
Save
Share
Report

The DOM Input Tel autofocus Property in HTML DOM is used to set or return whether the Input tel Field should get focused or not when the page loads. It reflects the HTML autofocus attribute.

Syntax:  

  • It returns the autofocus property.
telObject.autofocus
  • It is used to set the autofocus property.
telObject.autofocus = "true|false"

Property Values:  

  • true: It sets the focus of the tel field.
  • false: It has the default value. It defines that the tel field does not get focused.

Return Value: It returns a boolean value that represents whether the input tel field gets autofocus or not.

Example: This example illustrates how to get and set the Input tel autofocus property.   

HTML




<!DOCTYPE html>
<html>
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
    <h2> DOM Input Tel autofocus Property </h2>
    <input type="tel" id="mytel"
           value="6753682635" autofocus>
    <br><br>
    <button onclick="getFocus()">
        check autofocus!
    </button>
    <button onclick="setFocus()">
        Set autofocus!
    </button>
    <p id="demo"></p>
 
    <p id="sudo"></p>
 
    <script>
        function getFocus() {
            var x =
                document.getElementById("mytel").autofocus;
            document.getElementById(
                "demo").innerHTML = x;
        }
        function setFocus() {
            var x =
                document.getElementById("mytel").autofocus = "false";
            document.getElementById(
                "sudo").innerHTML = x;
        }
    </script>
</body>
</html>


Output: 

 

Supported Browsers:

  • Google Chrome 3 and above
  • Edge 12 and above
  • Firefox
  • Opera 11 and above
  • Safari 4 and above


Last Updated : 29 Aug, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads