querySelectorAll()
returns a static (not live) NodeList representing a list of the document’s elements that match the specified group of selectors. Use array#from
to convert NodeList to array then iterate through array#map
.
let list = document.querySelectorAll("li");
let items = Array.from(list).map(elem => {
console.log(elem);
})
<ul class="wrapper1" id="testDiv">
<li class="cake">Carrots</li>
<li class="cake">Cake</li>
<li class="cake">Wheat</li>
<li class="cake">Balloons</li>
</ul>