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

all collection

Browser support:
Represents a collection of all elements contained by an element or the entire document.
The elements in the collection are sorted in source code order.
The all collection is not supported by Firefox. For a cross-browser solution, to get elements by name or id, use the getElementsByName and getElementById methods, to get all child elements of an element, use the childNodes collection.

Syntax:

Properties that reference the object:
object.all
The base interface, through which you can add new functionalities to the all 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 element.
  • If more than one match is found, it returns an all sub-collection filled with the matching elements. The sub-collection contains the matching elements in source order.
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.
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 all 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 and Opera, and returns undefined in Google Chrome and Safari.
  • If exactly one match is found, it returns the matching element.
  • If more than one match is found, it returns an all 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 and Opera, and returns undefined in Google Chrome and Safari.
  • If exactly one match is found, it returns the matching element.
  • If more than one match is found, it returns an all sub-collection filled with the matching elements. The sub-collection contains the matching elements in source order.
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 all collection:
<head>
    <script type="text/javascript">
        function GetTableInnerHTML () {
            if (document.all) {  // Internet Explorer, Opera, Google Chrome and Safari
                var table = document.all.namedItem ("myTable");
            } 
            else {
                var table = document.getElementById ("myTable");
            }
            alert (table.innerHTML);
        }
    </script>
</head>
<body>
    <button onclick="GetTableInnerHTML ();">Get the innerHTML of the table!</button>
    <br /><br />
    <table id="myTable" border="1px">
        <tbody>
            <tr>
                <td>First row in the table.</td>
            </tr>
        </tbody>
    </table>
</body>
Did you find this example helpful? yes no

External links:

User Contributed Comments

Post Content

Post Content