Prop Htmlcollection Length
# HTMLCollection length Property
[ DOM HTMLCollection](#)
* * *
## Definition and Usage
The length property returns the number of elements in an HTMLCollection object.
This property is read-only.
This property is useful when looping through an HTMLCollection object.
## Syntax
HTMLCollection.length
### Return Value
Returns a number representing the number of elements in the HTMLCollection object.
* * *
## Browser Support
| Property | | | | | |
| --- | --- | --- | --- | --- | --- |
| length | Yes | Yes | Yes | Yes | Yes |
* * *
## Example
## Example
Loop through all elements with class="myclass" and change their background color:
var x = document.getElementsByClassName("myclass"); for(i = 0; i<x.length; i++){x.item(i).style.backgroundColor = "red"; }
[Try it Yourself Β»](#)
* * *
## Related Articles
HTMLCollection: [item()](#) Method
HTML Element: [getElementsByClassName()](#) Method
HTML Element: [getElementsByTagName()](#) Method
* * DOM HTMLCollection](#)
YouTip