DOM Interfaces

HTMLCollection

Live ordered collection of elements. DOM changes update membership automatically. It is not an Array; use Array.from for a stable snapshot before mutating the DOM. Example result: 3.

Formal Syntax & Structure

html syntaxhtml
element.children

Return Value

HTMLCollection

Live element collection.

Working Example

Example Snippethtml
<div id="items">  <span id="first">A</span>  <span>B</span></div><p>  Result:  <output id="result"></output></p><script>  const result = document.getElementById("result");  (async () => {  const items = document.getElementById("items"); const list = items.children;  items.append(document.createElement("span")); result.textContent = list.length;  })().catch(error => { result.textContent = "Error: " + error.name; });</script>
HTML Reference