HTML | DOM Image name Property

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Before Clicking On Button:

After Clicking On Button:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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

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.