I want to attach the "click" event to all button inside a div. Except this:
var div1 = document.getElementById("div1");
var elements = div1.getElementsByTagName('button');
for(var i = 0, len = elements.length; i < len; i++) {
elements[i].onclick = function () {
// stuff
}
}
Is there a better way to attach "onclick" function handler to all the buttons at once in pure js?