So maybe I\'m just not looking in the right places but I can\'t find a good explanation of how to do the equivalent of jQuery\'s
$(\'a\').click(function(){
I just stumbled upon this old question.
For new browsers (find support here: https://caniuse.com/?search=querySelectorAll)
My solution would be:
function clickFunction(event) {
// code here
}
for (let elm of document.querySelectorAll("a")) {
elm.onclick = clickFunction;
}
This is optimized to not create a new function for each element.
Will work on IE9 and up.