50
rated 0 times
[
56]
[
6]
/ answers: 1 / hits: 101823
/ 10 Years ago, tue, june 17, 2014, 12:00:00
In my JSFiddle, I’m simply trying to iterate over an array of elements. The array is non-empty, as the log statements prove. Yet the call to forEach
gives me the (not so helpful) “Uncaught TypeError
: undefined
is not a function” error.
I must be doing something stupid; what am I doing wrong?
My code:
var arr = document.getElementsByClassName('myClass');
console.log(arr);
console.log(arr[0]);
arr.forEach(function(v, i, a) {
console.log(v);
});
.myClass {
background-color: #FF0000;
}
<div class=myClass>Hello</div>
More From » foreach