You are here: Reference > JavaScript > client-side > HTML DOM > objects > areas

areas collection

Browser support:
Represents a collection of all area elements in a map element.
The elements in the collection are sorted in source code order.
If you need a collection of all area elements that have a href property specified, use the links collection.

Syntax:

Properties that reference the object:
map.areas
The base interface, through which you can add new functionalities to the areas collection, is the HTMLCollection interface.

Possible members:

Properties:
length
Returns an integer that specifies the number of elements in the current collection.

This property is read-only.
Methods:
[nameOrIndex]
Returns an element or a collection of elements from the current collection by name or index.

Parameters:

nameOrIndex
Required. A string or a zero-based integer that specifies the element or elements to retrieve.
  • If an integer value is specified, it specifies the index of the element to retrieve.
  • If this parameter is a string, then it specifies a value for the name or id property of the element or elements to retrieve.

Return value:

  • If no match is found, it returns undefined.
  • If exactly one match is found, it returns the matching area element.
  • If more than one match is found, it returns an areas sub-collection filled with the matching elements. The sub-collection contains the matching elements in source order.
In Firefox, if more than one match is found, the first matching element is returned.
add (element [, index])
Inserts an area element into the current collection at the specified position.

Parameters:

element
Required. Reference to the area element to add.
index
Optional. A zero-based integer that specifies the position of the insertion.
If index parameter is not specified, the add method inserts the area element into the end of the current collection.

Return value:

This method has no return value.
item (nameOrIndex [, subIndex])
Returns an element or a collection of elements from the current collection by name or index.

Parameters:

nameOrIndex
Required. A string or a zero-based integer that specifies the element or elements to retrieve.
  • If an integer value is specified, it specifies the index of the element to retrieve.
  • If this parameter is a string, then it specifies a value for the name or id property of the element or elements to retrieve.
Firefox does not support string values.
subIndex
Optional. Supported by Internet Explorer only. If more than one matching element is found for the index parameter (possible only if it is a string), the item method creates an areas sub-collection filled with the matching elements. In that case, the subIndex property specifies the position of the element in the sub-collection to retrieve. In other cases, the subIndex property has no meaning.

Return value:

  • If no match is found, it returns null in Internet Explorer, Firefox and Opera, and returns undefined in Google Chrome and Safari.
  • If exactly one match is found, it returns the matching area element.
  • If more than one match is found, it returns an areas sub-collection filled with the matching elements. The sub-collection contains the matching elements in source order.
namedItem (name)
Returns an element or a collection of elements from the current collection by name.

Parameters:

name
Required. String that specifies a value for the name or id property of the element or elements to retrieve.

Return value:

  • If no match is found, it returns null in Internet Explorer, Firefox and Opera, and returns undefined in Google Chrome and Safari.
  • If exactly one match is found, it returns the matching area element.
  • If more than one match is found, it returns an areas sub-collection filled with the matching elements. The sub-collection contains the matching elements in source order.
In Firefox, if more than one match is found, the first matching element is returned.
remove (index)
Removes the area element at the specified position from the current collection.

Parameters:

index
Required. A zero-based integer that specifies the position of the element to remove.

Return value:

This method has no return value.
tags
Returns a NodeList collection that contains all elements from the current collection with the specified tag name.
urns
Returns a NodeList collection that contains all elements to which the specified behavior is attached.

Example HTML code 1:

This example illustrates the use of the areas collection:
<head>
    <script type="text/javascript">
        function GetAreas () {
            var map = document.getElementById ("myMap");
            var message = "";
            for (i = 0; i < map.areas.length; i++) {
                message += i + ". area shape: " + map.areas.item (i).shape + "\n";
            }
            alert (message);
        }
    </script>
</head>
<body>
    <img src="area.gif" width=504 height=126 border=0 alt="Solar System" usemap="#SampleMap">
    <map name="SampleMap" id="myMap">
        <area shape="rect" coords="1,-1,83,125" alt="rectangle" href="#">
        <area shape="circle" coords="234,57,30" alt="circle" href="#">
        <area shape="poly" coords="363,37,380,40,399,35,420,47,426,63,423,78,430,94,409,90,395,92,379,84,371,67,370,57" alt="polygon" href="#">
    </map>
    <button onclick="GetAreas ();">Get areas!</button>
</body>
Did you find this example helpful? yes no

External links:

User Contributed Comments

Post Content

Post Content