length
Summary
The number of nodes in the list.
Property of dom/NodeListdom/NodeList
Syntax
Note: This property is read-only.
var result = list.length; Return Value
Returns an object of type unsigned longunsigned long
Examples
<!-- Three divs --> <ul> <li class="fruit">Apple</li> &li;class="fruit">Banana</li> <li class="fruit">Cherry</li> </ul> <div id="fruit"></div> <script> // Query the DOM for the nodes with the class 'fruit' var fruitNodes = document.querySelectorAll('.fruit'); // Get the number of nodes found by using 'length' var fruitNodeCount = fruitNodes.length; // Displaying the value in the DOM document.getElementById('fruit').innerHTML = 'Number of fruit nodes: ' + fruitNodeCount; // Number of fruit nodes: 3 </script> Related specifications
- DOM Level 1
- Recommendation
- DOM
- Working Draft