# DOM HTMLCollection
HTMLCollection is a collection of HTML elements.
The HTMLCollection object is similar to an array list containing HTML elements.
The [getElementsByTagName()](#) method returns an HTMLCollection object.
* * *
## Properties and Methods
The following table lists the properties and methods of the HTMLCollection object:
| Property / Method | Description |
| --- | --- |
| [item()](#) | Returns the element at the specified index in the HTMLCollection. |
| (#) | Returns the number of elements in the HTMLCollection. |
| [namedItem()](#) | Returns the element with the specified ID or name attribute in the HTMLCollection. |
* * *
## Examples
Returns a collection of all `
` elements, which is an HTMLCollection object:
## Example
var x = document.getElementsByTagName("p");
[Try it Β»](#)
Calculate the number of `
` elements in the document:
## Example
var x = document.getElementsByTagName("P"); document.write(x.length);
[Try it Β»](#)
Loop through and output all elements in the HTMLCollection object:
## Example
var x, i, l; x = document.getElementsByTagName("*"); l = x.length; for(i = 0; i<l; i++){document.write(x.tagName + "
"); }
[Try it Β»](#)