Is it possible to set the same onclick event to all elements of the same class / tag / etcetera? The following code does not work.
document.getElementsByTagName("A").onclick = function(){alert("!")};
Is it possible to set the same onclick event to all elements of the same class / tag / etcetera? The following code does not work.
document.getElementsByTagName("A").onclick = function(){alert("!")};
Yes you can loop each element and assign your listener
var elements = document.getElementsByTagName("a");
for(var i=0; i<elements.length; ++i) {
elements[i].addEventListener("click", function(event) {
alert(elements[i].nodeValue);
}, false);
}