Languages
[Edit]
EN

JavaScript - console.log NodeList elements

0 points
Created by:
starcraf35
754

In this article, we would like to show you how to print NodeList in the console in JavaScript.

Practical example

In this example, we use for loop to iterate over the nodes NodeList and console.log textContent of each element from the list. 

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<body>
  <div id="container">Container text 1 <span>span text</span>Container text 2</div>
  <script>

    var container = document.querySelector('#container');
    
    var nodes = container.childNodes;
    for (let i = 0; i < nodes.length; ++i) {
        console.log(nodes[i].textContent);
    }

  </script>
</body>
</html>

 

References

  1. NodeList - Web APIs | MDN

Alternative titles

  1. JavaScript - print NodeList in the console
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join