Javascript Reference - HTML DOM Map name Property








The name property sets or gets the name attribute of an image-map.

The name attribute is associated with the <img>'s usemap attribute and creates a relationship between the image and the map.

Browser Support

name Yes Yes Yes Yes Yes

Syntax

Return the name property.

var v = mapObject.name 

Set the name property.

mapObject.name=name




Property Values

Value Description
name Set the name of an image-map

Return Value

A String type value representing the name of the image-map.

Example

The following code shows how to change the name of an image-map.


<!DOCTYPE html>
<html>
<body>
<!--  w w  w .j  a va  2s  . c o m-->
<img src="http://java2s.com/style/demo/border.png" width="145" 
   height="150" alt="myIDs" usemap="#myIDmap">

<map id="myIDmap" name="myIDmap">
  <area shape="rect" coords="0,0,82,126" alt="A" href="a.htm">
  <area shape="circle" coords="90,68,3" alt="B" href="b.htm">
  <area shape="circle" coords="124,60,8" alt="C" href="c.htm">
</map>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myIDmap").name = "newMapName";
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get the name of an image-map.


<!DOCTYPE html>
<html>
<body>
<!--   ww  w. j a  v  a2s  .  c om-->
<img src="http://java2s.com/style/demo/border.png" width="145" 
    height="126" alt="myIDs" usemap="#myIDmap">

<map id="myIDmap" name="myIDmap">
  <area shape="rect" coords="0,0,82,126" alt="A" href="a.htm">
  <area shape="circle" coords="90,60,3" alt="B" href="b.htm">
  <area shape="circle" coords="130,60,8" alt="C" href="c.htm">
</map>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myIDmap").name;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: