JavaScript Element children Property

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline
Instance property

What You’ll Learn

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

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.

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).

📝 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.

ItemDetail
TypeHTMLCollection
AccessRead-only property (collection updates with the DOM)
Iteratefor (const child of el.children)
RelatedchildElementCount, childNodes, firstElementChild
⚠️
Not an Array

children has no map / forEach. Convert with Array.from(el.children) when you need array helpers.

📋 MDN Loop Example Shape

MDN loops each child element and logs its tagName:

JavaScript
<div id="foo">
  <p>One</p>
  <span>Two</span>
  <strong>Three</strong>
</div>
JavaScript
const myElement = document.getElementById("foo");
for (const child of myElement.children) {
  console.log(child.tagName);
}
// P
// SPAN
// STRONG

Related learning: childElementCount, firstElementChild, and lastElementChild.

⚡ Quick Reference

GoalCode / note
Get listel.children
Countel.children.length (= childElementCount)
First childel.children[0] or el.children.item(0)
Loopfor (const child of el.children)
To arrayArray.from(el.children)
MDN statusBaseline Widely available

🔍 At a Glance

Four facts about Element.children.

Kind
get only

Instance

Type
HTMLCollection

Not Array

Live
yes

Auto updates

Baseline
widely

Jul 2015+

Examples Gallery

Examples follow MDN Element: children. Labs use a simple parent with nested tags so you can inspect the live collection safely.

📚 Getting Started

Read the collection and loop tag names like MDN.

Example 1 — Read children

Log the length and collection type for a parent element.

JavaScript
const myElement = document.getElementById("foo");
console.log(myElement.children.length);
console.log(myElement.children.constructor.name);
Try It Yourself

How It Works

length matches childElementCount. The object type is HTMLCollection, not Array or NodeList.

Example 2 — MDN for...of Loop

Log each child element’s tag name.

JavaScript
const myElement = document.getElementById("foo");
for (const child of myElement.children) {
  console.log(child.tagName);
}
Try It Yourself

How It Works

for...of walks the live collection in document order. Tag names are typically uppercase in HTML documents.

📈 Compare Nodes, Live Updates & Snapshot

See the childNodes difference, then watch the list stay live.

Example 3 — vs childNodes

Whitespace text nodes appear in childNodes but not in children.

JavaScript
const box = document.getElementById("box");
console.log({
  childrenLength: box.children.length,
  childElementCount: box.childElementCount,
  childNodesLength: box.childNodes.length
});
Try It Yourself

How It Works

Prefer children when you want tags only. Prefer childNodes when text and comments matter.

Example 4 — Live Collection

Appending a child updates the same HTMLCollection reference.

JavaScript
const list = document.createElement("ul");
const kids = list.children;
console.log(kids.length); // 0

const item = document.createElement("li");
item.textContent = "One";
list.appendChild(item);
console.log(kids.length); // 1
console.log(kids[0].tagName); // LI
Try It Yourself

How It Works

Because the collection is live, be careful when removing items inside a forward loop—indexes can shift.

Example 5 — Support Snapshot

Feature-detect and remember the Array conversion tip.

JavaScript
console.log({
  supported: "children" in Element.prototype,
  type: "HTMLCollection (not Array)",
  tip: "Use for...of or Array.from(el.children)",
  status: "Baseline Widely available (MDN)"
});
Try It Yourself

How It Works

Treat children as a live element list. Snapshot with Array.from when you need a stable copy.

🚀 Common Use Cases

  • Looping menu links, list items, or card sections.
  • Reading the first or last element child by index.
  • Building element-only helpers without filtering text nodes.
  • Pairing with childElementCount for empty checks plus listing.
  • Teaching the difference between elements and all child nodes.

🔧 How It Works

1

Parent holds mixed children

Elements plus possible text or comments.

DOM
2

children filters to elements

Only tags enter the live collection.

Filter
3

You loop or index the list

for...of, [0], or item(i).

Read
4

DOM changes stay in sync

Append or remove children and the collection updates.

📝 Notes

Browser Support

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).

Baseline Widely available
Google Chrome Supported
Yes
Microsoft Edge Supported
Yes
Mozilla Firefox Supported
Yes
Apple Safari Supported
Yes
Opera Supported
Yes
Internet Explorer Supported (legacy HTMLCollection)
Yes
children Baseline

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.

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.

Continue with classList, childElementCount, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use for...of to walk child elements
  • Prefer children over filtering childNodes
  • Use Array.from when you need array methods
  • Snapshot the list before mutating during a loop
  • Pair with childElementCount for empty checks

❌ Don’t

  • Call Array methods on children directly
  • Assume text nodes are included
  • Assign el.children = ... (read-only)
  • Mutate the live list carelessly mid-loop
  • Confuse it with childNodes

Key Takeaways

Knowledge Unlocked

Five things to remember about children

Live HTMLCollection of direct element children—not text or comments.

5
Core concepts
📝 02

HTMLCollection

not Array

Type
🔍 03

Loop tags

menus & lists

Use
04

Baseline

widely available

Status
🎯 05

Live list

auto updates

Tip

❓ Frequently Asked Questions

It returns a live HTMLCollection of all child elements of the element. Text and comment nodes are not included.
No. MDN marks Element.children as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
No. It is an HTMLCollection. You can loop with for...of and use length/item(), but Array methods need Array.from(el.children).
childNodes includes every child node (elements, text, comments). children includes only element children.
Yes. If you add or remove child elements later, the same HTMLCollection reflects those changes.
el.children.length equals el.childElementCount. children gives you the list; childElementCount gives only the number.
Did you know?

Like childElementCount, children comes from the ParentNode mixin—so Document and DocumentFragment expose it too.

Next: classList

Learn how to add, remove, and toggle CSS classes safely.

classList →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful