Element.children is a read-only instance property that returns a live HTMLCollection of child elements. Learn how to loop tags, how it differs from childNodes, and how it pairs with childElementCount—with five examples and try-it labs.
01
Kind
Instance property
02
Access
Read-only
03
Type
HTMLCollection
04
Includes
Element children
05
Status
Baseline widely
06
Live?
Yes
Fundamentals
Introduction
When you need the list of nested tags inside a parent—not the count alone— children is the collection to use. It skips text and comment nodes and keeps only elements.
That makes it ideal for looping menu items, list rows, or card sections without tripping over whitespace from pretty-printed HTML.
JavaScript
const myElement = document.getElementById("foo");
for (const child of myElement.children) {
console.log(child.tagName);
}
💡
Beginner tip
Need every node including text? Use childNodes. Need only tags? Use children.
Concept
Understanding the Property
MDN: the read-only children property returns a live HTMLCollection which contains all of the child elements of the element upon which it was called.
Read-only — mutate the DOM to change membership.
HTMLCollection — live, ordered list of element children.
Elements only — excludes text and comment nodes.
Baseline — widely available since July 2015 (MDN).
Foundation
📝 Syntax
JavaScript
children
Value
An HTMLCollection: a live, ordered collection of child DOM elements. Access items with item(index) or array-style children[0]. If there are no element children, length is 0.
Item
Detail
Type
HTMLCollection
Access
Read-only property (collection updates with the DOM)
Iterate
for (const child of el.children)
Related
childElementCount, childNodes, firstElementChild
⚠️
Not an Array
children has no map / forEach. Convert with Array.from(el.children) when you need array helpers.
Pattern
📋 MDN Loop Example Shape
MDN loops each child element and logs its tagName:
Element.children is Baseline Widely available (MDN: across browsers since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Element.children
Read-only — live HTMLCollection of child elements (ignores text/comment nodes).
BaselineWidely available
Google ChromeSupported
Yes
Microsoft EdgeSupported
Yes
Mozilla FirefoxSupported
Yes
Apple SafariSupported
Yes
OperaSupported
Yes
Internet ExplorerSupported (legacy HTMLCollection)
Yes
childrenBaseline
Bottom line: Use children to list element children. Prefer it over childNodes when whitespace text would get in the way. Loop with for...of or convert with Array.from.
Wrap Up
Conclusion
children is your live list of nested tags. Loop it with for...of, index it like an array, and remember it ignores text nodes—unlike childNodes.