YouTip LogoYouTip

Coll Map Areas

# Map areas Collection [![Image 8: Map Object Reference](#) Map Object](#) ## Example Get the number of elements in an image map: var x = document.getElementById("planetmap").areas.length; The _x_ output will be: 3 [Try it Β»](#) * * * ## Definition and Usage The areas collection returns a collection of all elements in an image map. **Note:** The elements in the collection are sorted in the same order as they appear in the source code. **Tip:** If you need to return a collection of the specified href attributes of all elements, you need to use the (#) collection. * * * ## Browser Support ![Image 9: Internet Explorer](#)![Image 10: Firefox](#)![Image 11: Opera](#)![Image 12: Google Chrome](#)![Image 13: Safari](#) All major browsers support the areas collection. * * * ## Syntax _mapObject_.areas ## Properties | Property | Description | | --- | --- | | length | Returns the number of elements in the collection | ## Methods | Method | Description | | --- | --- | | | A string or integer that specifies the element to retrieve (index starts at 0) | | item(_name_or_index_) | Returns the element at 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 Get the URL of the first element in an image map: var x = document.getElementById("planetmap").areas.href; [Try it Β»](#) ## Example item(_name_or_index_) Get the URL of the first element in an image map: var x = document.getElementById("planetmap").areas.item(0).href; [Try it Β»](#) ## Example namedItem(_name_or_id_) Get the URL of the element with id="myArea" in an image map: var x = document.getElementById("planetmap").areas.namedItem("myArea").href; [Try it Β»](#) ## Example Get the shape of all elements in an image map: var x = document.getElementById("planetmap"); var txt = ""; for (var i = 0; i < x.areas.length; i++) { txt = txt + x.areas.shape + "
"; } document.getElementById("demo").innerHTML = txt; [Try it Β»](#)
← Prop Map NameDom Obj Map β†’