DOM Properties
NodeList.length
Number of nodes in the list. A static list retains its original membership when nodes change. A list from querySelectorAll is static, whereas childNodes is live. Neither length nor numeric indexing tells you which kind of node is at a position; childNodes can include text and comment nodes. Example result: 2.
Formal Syntax & Structure
html syntaxhtml
list.lengthReturn Value
number
Number of nodes currently represented by this NodeList.
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.querySelectorAll("span"); result.textContent = list.length; })().catch(error => { result.textContent = "Error: " + error.name; });</script>