JavaScript Element children Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

Element.children is a read-only, live HTMLCollection of the element’s child elements (MDN). Text nodes and comments are not included.

Read the notes below before you get or set this property. Prefer feature detection when support is limited.

Syntax

Use el.children. Start with this line.

JavaScript
el.children
CallWhat it does
el.childrenPrimary signature.

Built into the browser. Read or assign el.children — no import required.

Library declarations
JavaScript
el.children

Parameters

ParameterDescription
Parent elementRequired. Owner of the child list

Return Value

Return ValueDescription
*Live HTMLCollection

JavaScript Examples

Example 1 — Loop with for...of (MDN)

Log every child element’s tag name.

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

How It Works

  1. Find the parent. getElementById returns the container.
  2. Read children. You get a live HTMLCollection of element kids only.
  3. Loop with for...of. Each iteration is an Element.
  4. Log tagName. Tag names are uppercase in HTML documents (for example "P").

Example 2 — Index and item()

Read the first and last element child by index.

JavaScript
const list = document.getElementById("list");
const kids = list.children;

console.log(kids.length);                 // 3
console.log(kids[0].textContent);         // "One"
console.log(kids.item(kids.length - 1).textContent); // "Three"
Try It Yourself

How It Works

  1. Cache the collection. const kids = list.children is fine — it stays live.
  2. Use length. Same value as childElementCount.
  3. Bracket access. kids[0] is the first element child.
  4. item() works too. kids.item(i) is the collection API form of the same access.

Example 3 — The Collection Is Live

Append a child and see the same children reference grow.

JavaScript
const box = document.getElementById("box");
const kids = box.children;

console.log(kids.length); // 1
box.appendChild(document.createElement("span"));
console.log(kids.length); // 2
console.log(kids[1].tagName); // "SPAN"
Try It Yourself

How It Works

  1. Capture once. kids points at the live collection.
  2. Append an element. Only element children change the list.
  3. Length updates. No need to re-read box.children.
  4. Careful in loops. If you add/remove while iterating, length changes under you — prefer a snapshot with Array.from when mutating.

Browser Support

Element.children is Baseline Widely available (MDN: across browsers since July 2015).

✓ Baseline · Widely available

Element.children

Supported in all modern browsers and long-standing engines. Safe for everyday DOM code.

99% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Android WebView Supported · Modern WebView
Full support
Element.children Excellent

Bottom line: Universally available. Prefer children over childNodes when you only want element kids.

Frequently Asked Questions

It returns a live HTMLCollection of the element’s child elements only. Text nodes and comments 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. It is array-like (length, [i], item(i)) but has no Array methods like map. Use for...of, or Array.from(el.children) when you need array helpers.
children includes only element nodes. childNodes includes every child node — elements, text, and comments. Whitespace between tags often appears in childNodes only.
Yes. If you append or remove element children, the same HTMLCollection updates automatically.
el.childElementCount equals el.children.length. Use the count when you only need the number; use children when you need the elements.

Next: classList

Learn the classList property — a live DOMTokenList for adding, removing, and toggling CSS classes.

classList tutorial →

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.

21 people found this page helpful