Object: HTMLCollection
The HTMLCollection object is an array that contains an ordered collection of nodes. HTMLCollection objects are automatically updated when the underlying document is changed.
You can access an individual node within a collection by its index position using HTMLCollection.item(), by its name or id attribute using HTMLCollection.namedItem(), or you can index the object directly. For example, if you create an instance of a HTMLCollection object called myHTMLNodes, then specifying
HTMLCollection properties
HTMLCollection methods
Method: HTMLCollection.item()
Parameters
Parameter |
Type |
Description |
|---|---|---|
index |
int |
The index position of the node to be returned. Valid values are between 0 and HTMLCollection.length-1 inclusive. |
Method: HTMLCollection.namedItem()
The namedItem() method retrieves the node with the given name from the collection.
This method behaves differently depending on the document type:
If the document is an HTML document, this method first searches for a node with an id attribute that matches the given name, then searches for a node with a name attribute that matches the given name if no matching id attribute exists.
When searching HTML documents, this method is case insensitive.
If the document is an XHTML document, this method only searches for nodes with an id attribute that matches the given name.
When searching XHTML documents, this method is case sensitive.