Map areas Collection namedItem(id) - Get the URL of the <area> element with id="myArea" in an image-map: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Map

Description

Map areas Collection namedItem(id) - Get the URL of the <area> element with id="myArea" in an image-map:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img src="http://java2s.com/resources/a.png" width="145" height="126" alt="" usemap="#myMap">

<map id="planetmap" name="planetmap">
  <area shape="rect" coords="0,0,80,130" alt="" href="">
  <area id="myArea" shape="circle" coords="90,60,5" alt="" href="">
  <area shape="circle" coords="120,60,10" alt="" href="">
</map>//from  w  w w  .  java 2  s . c om

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

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

<script>
function myFunction() {
    var x = document.getElementById("planetmap").areas.namedItem("myArea").href;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials