Open In App

HTML | DOM Image name Property

Last Updated : 15 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads