I was searching for a simple click event script without the use of jQuery, and found some usefull code. With this I created my own variant of this code, which works, but there is one thing I don't get
[].forEach.call(document.querySelectorAll("a"), function (el) {
el.addEventListener("click", function (ev) {
ev.preventDefault();
this.style.backgroundColor = "grey";
})
});
This code grabs all <a>
-elements on the webpage and adds a click event which changes the background colour to gray.
However, I don't get why forEach.call()
executes while the array []
is empty.
Could someone explain how this works?