forEach Element / Node

javascript

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) )

Reference

No known

History Jun 05, 2017