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:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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 Disabled Property. 
            var txt = document.getElementById(
                "myImage").autofocus;
            document.getElementById(
                "Geek_h").innerHTML = txt;
        }
    </script>
</body>
  
</html>

chevron_right


Output:

  • Before Clicking On Button:
  • After Clicking On Button:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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 Disabled Property. 
            var txt = document.getElementById(
                "myImage").autofocus = false;
            document.getElementById(
                "Geek_h").innerHTML = txt;
        }
    </script>
</body>
  
</html>

chevron_right


Output:

  • Before Clicking On Button:
  • After Clicking On Button:

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

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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.