EN
JavaScript - console.log NodeList elements
0
points
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>