forEach Element / Node


getElementsByTagName and all its cousins return an object similar to an array. However, without the array prototype methods

The cleanest solution is to add them

NodeList.prototype.forEach = HTMLCollection.prototype.forEach = Array.prototype.forEach

and you you're good to go

var nodes = document.getElementsByTagName('a') nodes.forEach(node => console.log(node) )


No known

History Jun 05, 2017