Javascript DOM HTML Map name Property set

Introduction

Change the name of an image-map:

document.getElementById("myFlagMap").name = "newMapName";

Click the button to change the name of the image-map.

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://java2s.com">
  <area shape="circle" coords="90,58,3" alt="Web" href="https://java2s.com">
  <area shape="circle" coords="50,50,40" alt="Target" href="https://www.java2s.com">
</map>/*w ww  .j a  v a  2  s . c om*/
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  document.getElementById("myFlagMap").name = "newMapName";
  document.getElementById("demo").innerHTML = "The value of the name attribute was changed.";
}
</script>

</body>
</html>



PreviousNext

Related