DOM HTMLCollection Interface
An HTMLCollection is a live list of elements, such as element.children or document.forms. It updates automatically when the page changes.
Description
An HTMLCollection is an array-like list of elements (never text nodes) returned by properties such as children, document.forms and document.images, and by getElementsByClassName() and getElementsByTagName(). It is always live: it changes as elements are added or removed, which can cause surprises when you modify the page while looping over it.
It has length, index access, item() and namedItem(), and works with for...of, but has no forEach(). Convert it with Array.from() for array methods or a stable copy.
Because the collection updates automatically, removing elements while looping over it forwards skips every other element; loop backwards, or copy the collection to an array first. Elements can also be looked up by their id or name through namedItem() or bracket notation, as in document.forms.signup.
Example
Browser Support
The following information will show you the current browser support for the HTMLCollection interface. Hover over a browser icon to see the version that first introduced support for this interface.
Desktop





Tablets & Mobile





