NodeList.forEach

by Lee Cooper

HTML

<div>
  <p>
    <a></a>
  </p>
  <a></a>
</div>

JavaScript

if (typeof(NodeList.prototype.forEach) !== 'function') {
    NodeList.prototype.forEach = function (func, argument) {
        let _this = argument || this;
        for (let i = 0; i < _this.length; i++) {
            func.call(_this, _this[i], i, _this);
        }
    };
}

document.querySelectorAll('a').forEach((e) => console.log(e));