Javascript DOM HTML Map name Property get

Introduction

Get the name of an image-map:

var x = document.getElementById("myFlagMap").name;

View in separate window

<!DOCTYPE html>
<html>
<body>

<img src="image1.png" width="145" height="126" alt="Planets" usemap="#myFlagMap">

<map id="myFlagMap" name="myFlagMap">
  <area shape="rect" coords="0,0,30,30" alt="Site" href="https://www.java2s.com">
  <area shape="circle" coords="90,90,10" alt="Web" href="https://www.java2s.com">
  <area shape="circle" coords="50,50,40" alt="Target" href="https://www.java2s.com">
</map>//  w  w  w .  ja  v  a2 s.co  m

<p>Click the button to get the name of the image-map.</p>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myFlagMap").name;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

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

The name attribute specifies the name of an image-map.

The name attribute is associated with the <img>'s usemap attribute.

It creates a relationship between the image and the map.

In HTML5, the id attribute of the <map> element must have the same value as the name attribute.

The name property accepts and returns a String type value.

The name property returns a String representing the name of the image-map.




PreviousNext

Related