Map areas Collection - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Map

Description

The areas collection returns all <area> elements in an image-map sorted as they appear in the source code.

Syntax

Properties

Property Description
length number of <area> elements in the collection.

Methods

MethodDescription
[index] <area> element with the specified index (starts at 0).
item(index) <area> element with the specified index (starts at 0).
namedItem(id) <area> element with the specified id.

Technical Details

Return Value:

An HTMLCollection Object, representing all <area> elements in an image-map in the document.

The following code shows how to Find out how many <area> elements there are in a specific 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 shape="circle" coords="90,60,5" alt="" href="">
  <area shape="circle" coords="120,60,10" alt="" href="">
</map>//from w  w  w  .  j  a  v  a  2s. c  o  m

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

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

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

</body>
</html>

Related Tutorials