CKTIS / JavaScript
NodeList.length — node count
NodeList.length is a read-only property reporting the number of nodes in a collection, not necessarily just elements.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
nodeList.lengthNodeList.length returns the collection's node count as a nonnegative integer; an empty collection has length 0. It is a read-only property, not a method: use nodeList.length, without parentheses. Indices start at 0 and end at length - 1.
The result depends on the collection. childNodes includes text and comment nodes. It is live, so its length reflects DOM changes. querySelectorAll() returns a static collection: later DOM changes do not update its length.
This is a DOM API, not an ECMAScript language feature. The example demonstrates both collections using a detached element.
Examples
const container = document.createElement("div");
container.appendChild(document.createTextNode("hello"));
container.appendChild(document.createElement("span"));
const live = container.childNodes;
const snapshot = container.querySelectorAll("span");
console.log(live.length, snapshot.length);
container.appendChild(document.createElement("span"));
console.log(live.length, snapshot.length);Result
2 1 3 1
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.