Map areas Collection - Loop through all <area> elements in an image-map and output the shape of each area: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Map

Description

Map areas Collection - Loop through all <area> elements in an image-map and output the shape of each area:

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 shape="circle" coords="90,60,5" alt="" href="">
  <area shape="circle" coords="120,60,10" alt="" href="">
</map>/*from  w w  w .  ja v a  2  s  . co m*/

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

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

<script>
function myFunction() {
    var x = document.getElementById("planetmap");
    var txt = "";
    var i;
    for (i = 0; i < x.areas.length; i++) {
        txt = txt + x.areas[i].shape + "<br>";
    }

    document.getElementById("demo").innerHTML = txt;
}
</script>

</body>
</html>

Related Tutorials