nodes in the document: ## Example var myNodeList = document.querySelectorAll("p"); Elements in a NodeList can be accessed by index (starting at 0). Accessing the second
element can be done with the following code: y = myNodeList; [Try it Β»](#) * * * ## NodeList Object length Property The NodeList object length property defines the number of elements in the node list. ## Example var myNodelist = document.querySelectorAll("p"); document.getElementById("demo").innerHTML = myNodelist.length; [Try it Β»](#) ### Example Explained Get the collection of
elements: var myNodelist = document.querySelectorAll("p"); Display the number of elements in the node list: document.getElementById("demo").innerHTML = myNodelist.length; The length property is often used to loop through a node list. ## Example Change the background color of all
elements in the node list: var myNodelist = document.querySelectorAll("p"); var i; for(i = 0; i **A NodeList is not an array!** > > > A NodeList might look like an array, but it is not. > > > You can use an index to access elements, just like an array. > > > A NodeList cannot use array methods: valueOf(), pop(), push(), or join(). >
YouTip