DOM - NodeList (Collection)

1 - About

A nodelist is the result of a selection that returns more than one node (Generally an element)

Nodelist:

  • HTMLAllCollection, HTMLFormControlsCollection, HTMLOptionsCollection, interfaces are collections derived from the HTMLCollection interface.

3 - Management

3.1 - Length

  • With JQuery

jQuery(selector).length

3.2 - Loop

  • A list of div element where we want to loop.

<ul id="my-list">
    <li>Nico</li>
    <li>can</li>
    <li>do</li>
    <li>JS</li>
</ul>

  • The Javascript code that shows the loop.

// Get all divs element
// allDivs is an array of NodeList
allDivs=document.querySelectorAll("#my-list > li");

// Loop
for (i = 0; i < allDivs.length; i++) {
    console.log("Li element number "+i+" - "+allDivs[i].textContent);
}

For more see DOM - Collection Iteration (NodeList, ..)

4 - Documentation / Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap