Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM Image name Property

  • Last Updated : 27 Aug, 2019

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

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

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :