Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Map areas collection

Map areas collection

Map Object Reference Map object

Example

Get the number of in the image map elements:

var x = document.getElementById("planetmap").areas.length;

x The output value is:

3

Try it »


Definition and usage

The areas collection returns all in the image map collection of elements.

Note: The elements in the collection are sorted in the order they appear in the source code.

Tip: If you need to return all elements, the specified href attribute collection, you need to use links collections.


Browser support

Internet Explorer Firefox Opera Google Chrome Safari

All major browsers support the areas collection.


Syntax

mapObject

.areas

property

property Description
length Returns the number of in the collection Number of elements

Method

Method Description
[name_or_index] A string or integer specifying the element to retrieve (index starts at 0)
item(name_or_index) Returns the element with the specified index/name/id from the collection
namedItem(name_or_id) Returns the element with the specified name from the collection (name or id attribute)

More examples

Example

[name_or_index]

Get the first in the image map element's URL:

var x = document.getElementById("planetmap").areas[0].href;

Try it »

Example

item(name_or_index)

Get the first in the image map element's URL:

var x = document.getElementById("planetmap").areas.item(0).href;

Try it »

Example

namedItem(name_or_id)

Get the in the image map with id="myArea" element URL:

var x = document.getElementById("planetmap").areas.namedItem("myArea").href;

Try it »

Example

Get all in the image mapelements' shapes:

var x = document.getElementById("planetmap");

var txt = "";

for (var i = 0; i < x.areas.length; i++)

  {

  txt = txt + x.areas[i].shape + "
";

  }

document.getElementById("demo").innerHTML = txt;

Try it »


Map Object Reference Map object