4 ms·
Except #forEach is a method of Array, and getElementsByTagName does not return an Array but a NodeList. Which doesn't have any of Array's methods (it has a leng
by masklinn 14y ago
Except #forEach is a method of Array, and getElementsByTagName does not return an Array but a NodeList. Which doesn't have any of Array's methods (it has a length, it can be indexed, and it has an alternative indexation method - #item — but it's not an array at all)
- nailer 14y agoYou're right. I wasn't sure earlier, as I was typing on a phone with no JS console. but never mind: Array.forEach.call(paragraphs, function(paragraph){paragraph.innerHTML = 'Hello.';}) will work fine.