Get Map Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Map

Introduction

The Map object represents an HTML <map> element.

You can access a <map> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img src="http://java2s.com/resources/c.png" width="100" height="100" alt="Planets" usemap="#myMap">

<map id="myMap" name="myMap">
  <area shape="rect" coords="0,0,80,100" alt="alt message" href="http://java2s.com/resources/a.png">
  <area shape="circle" coords="90,58,3" alt="alt message" href="http://java2s.com/resources/a.png">
  <area shape="circle" coords="120,50,10" alt="alt message" href="http://java2s.com">
</map>//from   w ww .  jav  a  2 s  .  co  m

<button onclick="myFunction()">get the number of area elements in the image-map</button>

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

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

</body>
</html>

Related Tutorials