Open In App

HTML DOM Map name Property

The Map name property in HTML DOM is used to set or return the value of the name attribute of a map element. This attribute specifies the name of the mapping image. This attribute is associated with <img> usemap attribute. It creates a relationship between the <image> and <map> elements. 

Syntax:



mapObject.name
mapObject.name = name

Property Values:

Return Value: It returns a string value that represents the name of the map element. 



Example: 




<!DOCTYPE html>
<html>
   
<head>
    <title>
        HTML DOM Map name Property
    </title>
</head>
 
<body>
    <h2>
        GeeksForGeeks
    </h2>
 
    <h3>
        HTML DOM Map name Property
    </h3>
     
    <h4>Click the button</h4>
     
    <map id = "Geeks" name = "Geeks">
         
        <area shape = "rect" coords = "0, 0, 110, 100"
                alt = "Geeks" href =
 
        <area shape = "rect" coords = "110, 0, 190, 100"
                alt = "For" href =
 
        <area shape = "rect" coords = "190, 0, 300, 100"
              alt = "GEEKS"  href =
    </map>
     
    <img src =
    width = "300" height = "100" alt="GFG" usemap = "#Geeks">
     
    <br><br>
     
    <button onclick = "GFG()">
        Click Here!
    </button>
     
    <p id = "GEEK!"></p>
     
    <script>
        function GFG() {
            let x = document.getElementById("Geeks").name;
            document.getElementById("GEEK!").innerHTML = x;
        }
    </script>
</body>
   
</html>

Output:

 

Example 2: 




<!DOCTYPE html>
<html>
   
<head>
    <title>
        HTML DOM Map name Property
    </title>
</head>
   
<body>
    <h2>
        GeeksForGeeks
    </h2>
 
    <h3>
        HTML DOM Map name Property
    </h3>
     
    <h4>Click the button</h4>
     
    <map id = "Geeks" name = "Geeks">
         
        <area shape = "rect" coords = "0, 0, 110, 100"
                alt = "Geeks" href =
 
        <area shape = "rect" coords = "110, 0, 190, 100"
                alt = "For" href =
 
        <area shape = "rect" coords = "190, 0, 300, 100"
                alt = "GEEKS" href =
    </map>
     
    <img src =
    width = "300" height = "100" alt="GFG" usemap = "#Geeks">
     
    <br><br>
     
    <button onclick = "GFG()">
        Click Here!
    </button>
     
    <p id = "GEEK!"></p>
     
    <script>
        function GFG() {
            let x = document.getElementById("Geeks").name
                    = "Hello Geeks";
             
            document.getElementById("GEEK!").innerHTML
                    = "The name was changed to " + x;
        }
    </script>
</body>
   
</html>

Output:

 

Supported Browsers: The browsers supported by HTML DOM Map name property are listed below:


Article Tags :