foreach addeventlistener code example
Example: how to add event listener to all buttons
//HTML
//JavaScript
var buttons = document.querySelectorAll(".btn").length;
for (var i = 0; i < buttons ; i++) {
document.querySelectorAll(".btn")[i].addEventListener("click", function() {
alert("Button Clicked");
});
}