The Areas Collection

Note : The Areas collection is Internet Explorer specific. Netscape includes all <AREA> element objects in the Links collection. For properties, methods and events that are supported by <AREA> element, see the Client Side Image Maps topic.

The Areas collection is an ordered, indexed array, containing a reference to every <AREA> element in a given <MAP> element. A separate Areas collection is available for each different <MAP> element in the document and the Areas collection can only be referenced through a reference to a valid <MAP> element object.

Area Objects would normally be retrieved by their index in the Areas collection. I.e.:


returns the HREF attribute of the second <AREA> element in the <MAP> element referenced by <MAP>reference. For example, consider the following:

<MAP NAME="Map1">
<AREA SHAPE="circle" COORDS="52,49,35" HREF="index.htm">
<AREA SHAPE="rect" COORDS="53,34, 131,82" HREF="start.htm">

Calling the following in a script function:


would return start.htm. (Note that the <MAP> element doesn't have to be referenced through the All Collection)

A string value can be used however, as long as that string is a valid identifier (ID attribute value) for an <AREA> element in the referenced <MAP> element in the document.



would return the TITLE attribute of the <AREA> whose NAME, or ID property is 'Area1', in the <MAP> element referenced by <MAP>reference.


The length property returns the number of areas in the collection. Note that the length count starts at 1, not 0 as the areas collection index does. Therefore, the length property may return a value of 5, but to access the 3rd area in a <MAP>, you'd need to use document.<MAP>reference.areas(2).property


The item method retrieves single items, or sub-collections from an areas collection. It accepts the following arguments:

areas.item(index, sub-index)

If index is a number, then the method returns a reference to the <AREA> at that position in the areas collections index. I.e.


would make strTag be the value of the TITLE attribute of the <MAP>'s third <AREA>. As you can see, this is effectively the long-hand version of using document.<MAP>reference.areas(2).property.

If the index property is a string value, then the item method returns a sub-collection, containing a reference to every area in the map that has its NAME or ID attribute set to the string contained in the index argument. To retrieve certain element objects from this sub-collection, the sub-index argument must be used.