In my HTML, I have some elements with the class node-item
. To access them in my component, I use the following code:
let nodeItems = document.getElementsByClassName('node-item');
When I log nodeItems
, it shows me a HTMLCollection[]
containing 4 items.
Despite trying different methods, I am unable to iterate over the nodeItems
:
1. First Attempt:
let bar = [].slice.call(nodeItems);
for (var g of bar){
console.log(g); //does not output anything
}
2. Second Attempt:
for(let c of <any>nodeItems) {
console.log(c); //still does not display anything
}
I have also experimented with array and object iteration, but kept getting undefined
or an error
. Additionally, I attempted:
let nodeItems = document.querySelector(selectors);
However, this did not resolve the issues either.