In an angular app I am using plain JS to get the elements by class name Code:
var testElements = document.getElementsByClassName("project-link");
console.log(testElements);
this prints as such:
[item: function, namedItem: function]
0: a.project-link.ng-binding
1: a.project-link.ng-binding
...
30: a.project-link.ng-binding
length: 32
__proto__: HTMLCollection
However. if I try printing an item alone, this returns null:
console.log(testElements.item(4));
null
I don't understand what is wrong with this code, I have also tried the Array.prototype.filter.call function and it doesn't work either. Any ideas?
I fixed this bug by adding my code inside the window load function:
window.addEventListener("load", function(event) {
// your code ....
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With