Get Map Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Map


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>

<img src="" 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="">
  <area shape="circle" coords="90,58,3" alt="alt message" href="">
  <area shape="circle" coords="120,50,10" alt="alt message" href="">
</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>

function myFunction() {
    var x = document.getElementById("myMap").areas.length;
    document.getElementById("demo").innerHTML = x;


Related Tutorials