Skip to content
Related Articles

Related Articles

HTML | DOM Input image autofocus Property

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 21 Jun, 2022

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: 

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

Property values:

  • true: It sets the focus of Input Image.
  • false: It is the default value. It defines the Input Image field does not get focus.

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

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

html




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

  • Before Clicking On Button:

  • After Clicking On Button:

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

html




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

  • Before Clicking On Button:

 

  • After Clicking On Button:

 

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

  • Google Chrome 10.0
  • Firefox 4.0
  • Opera 11.0
  • Safari 5.1

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!