Skip to content
Related Articles

Related Articles

HTML | DOM Image name Property

View Discussion
Improve Article
Save Article
  • Last Updated : 15 Sep, 2022
View Discussion
Improve Article
Save Article

The Image name Property in HTML DOM is used for setting or returning the value of the name Attribute of an <image> element. 

Note: This property is not supported by HTML 5. 

Syntax: 

imageObject.name

Property Values:

  • name: It specifies the name of the Image.

Return Value: It returns a string value which represents the name of the Image. 

Example-1: This Example returns an Image name Property. 

HTML




<!DOCTYPE html>
<html>
 
<body>
    <center>
        <img src=
            id="image" alt="" width="250"
            height="205" name="geeks"
            class="alignnone size-medium wp-image-1092360" />
        <br><br>
         
        <button type="button" onclick="getHeight()">
            Click
        </button>
        <h4 id="text"></h4>
    </center>
 
    <script>
        function getHeight() {
            var imgObject =
                document.getElementById("image");
            var output =
                document.getElementById("text");
            output.innerHTML = "The name of the image is : "
                + imgObject.name;
        }
    </script>
</body>
 
</html>

Before Clicking On Button:

  

After Clicking On Button:

  

Example-2: This Example sets the Image name Property. 

HTML




<!DOCTYPE html>
<html>
 
<body>
    <center>
        <img src=
            id="image" alt="" width="250"
            height="205" name="geeks"
            class="alignnone size-medium wp-image-1092360" />
        <br><br>
 
        <button type="button" onclick="getHeight()">
            Click
        </button>
        <h4 id="text"></h4>
    </center>
     
    <script>
        function getHeight() {
            var imgObject =
                document.getElementById(
                    "image").name = "Hello Geeks";
 
            var output =
                document.getElementById(
                    "text").innerHTML =
                "The name of the image was changed to "
                + imgObject;
        }
    </script>
</body>
 
</html>

Before Clicking On Button:

  

After Clicking On Button:

  

Supported Browsers: The browsers supported by DOM Image name Property are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Apple Safari
  • Opera

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!