Map areasCollection

Map 对象参考手册Map ObjectMap Object

Examples

Get the number of <area> elements in the image map:

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

xThe output value is:

3

Try it Yourself »

Definition and Usage

The areas collection returns a collection of all <area> elements in the image map.

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

Tip:If you need to return a collection of the specified href attributes in all <area> elements, you need to use thelinkscollection.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

All major browsers support the areas collection.


Syntax

mapObject.areas

Properties

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

Methods

Method Description
[name_or_index] 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 URL of the first <area> element in the image map:

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

Try it Yourself »

Example

item(name_or_index)

Get the URL of the first <area> element in the image map:

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

Try it Yourself »

Example

namedItem(name_or_id)

Get the URL of the <area> element with id="myArea" in the image map:

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

Try it Yourself »

Example

Get the shapes of all <area> elements in the image map:

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

Try it Yourself »


Map 对象参考手册Map ObjectMap Object

Other Extensions