JSFiddle - React, Tailwind, and code Playground
HTML
<html>
<body>
<div id="msgs"></div>
<div id="cont">
<div class="foo">not yet visited</div>
<div class="foo">not yet visited</div>
</div>
<div class="foo">should never be visited</div>
</body>
</html>
JavaScript
NodeList.prototype.forEach = function(cb) {
for (var i = 0; i < this.length; i++) {
cb(this[i]);
}
}
var cont = document.getElementById('cont');
cont.getElementsByClassName('foo').forEach(function (item) {
console.log(item);
item.textContent = 'visited';
});
/* In Firefox, the forEach is never added to the prototype? Test fails
Turns out getElementsByClassName is returning an HTMLCollection
and not a NodeList... fail. Bug was reported in 1999:
https://bugzil.la/14869
*/