Open In App

HTML DOM Input Tel autofocus Property

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:  



telObject.autofocus
telObject.autofocus = "true|false"

Property Values:  

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.   




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


Article Tags :