Map areasCollection
Map ObjectMap Object
Examples
Get the number of <area> elements in the image map:
xThe output value is:
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
![]()
All major browsers support the areas collection.
Syntax
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:
Try it Yourself »
Example
item(name_or_index)
Get the URL of the first <area> element in the image map:
Try it Yourself »
Example
namedItem(name_or_id)
Get the URL of the <area> element with id="myArea" in the image map:
Try it Yourself »
Example
Get the shapes of all <area> elements in the image map:
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 ObjectMap Object