Open In App

HTML | DOM Input image autofocus Property

The HTML DOM input Image autofocus Property is used to set or return whether the Input Image Field should get focus or not when the page loading. It reflects the HTML autofocus attribute. 

Syntax: 



imageObject.autofocus
imageObject.autofocus = "true|false"

Property values:

Return value: It returns the boolean value which represents the image field gets autofocus or not. 



Example 1: This example returns the Input Image autofocus property. 




<!DOCTYPE html>
<html>
<head>
    <title>
        HTML DOM Input Image autofocus Property
    </title>
</head>
<body style="text-align:center;">
    <h1 style="color:green;">
      GeeksforGeeks
    </h1>
    <h4>
      DOM Input Image autofocus Property
    </h4>
    <input id="myImage" formEnctype="application/x-www-form-urlencoded"
           type="image" formtarget="#" src=
           alt="Submit" width="48" height="48" formMethod="post"
           autofocus>
    <br>
    <br>
    <button onclick="my_geek()">Submit </button>
    <h2 id="Geek_h" style="color:green;">
    </h2>
    <script>
        function my_geek() {
 
            // return autofocus Property.
            var txt = document.getElementById(
                "myImage").autofocus;
            document.getElementById(
                "Geek_h").innerHTML = txt;
        }
    </script>
</body>
</html>

Output:

Example 2: This example sets the Input Image autofocus property. 




<!DOCTYPE html>
<html>
<head>
    <title>
        HTML DOM Input Image autofocus Property
    </title>
</head>
<body style="text-align:center;">
    <h1 style="color:green;">
            GeeksforGeeks
    </h1>
    <h4>DOM Input Image autofocus Property</h4>
    <input id="myImage" formEnctype="application/x-www-form-urlencoded"
           type="image" formtarget="#" src=
           alt="Submit" width="48" height="48" formMethod="post"
           autofocus>
    <br>
    <br>
    <button onclick="my_geek()">Submit </button>
    <h2 id="Geek_h" style="color:green;">
    </h2>
    <script>
        function my_geek() {
 
            // set autofocus Property.
            var txt = document.getElementById(
                "myImage").autofocus = false;
            document.getElementById(
                "Geek_h").innerHTML = txt;
        }
    </script>
</body>
</html>

Output:

 

 

Supported Browsers: The browsers supported by HTML DOM Input image autofocus Property are listed below:


Article Tags :