What I'm trying to do here is to apply an eventListener to every element of one class, and then, after user clicked on one of those elements, he will be prompted dependent on the index of that element in the class array.
Also, yes, I know that it can be done in many different ways, but I want it to work in this particular one (if it is possible).
var buttons = document.getElementsByClassName("openbtn");
var i;
for (i = 0; i < buttons.length; i += 1) {
buttons[i].addEventListener("click", function () {
switchBtn(i);
});
}
function switchBtn(index) {
switch (index) {
case 0:
prompt("case0");
break;
case 1:
prompt("case1");
break;
default:
alert(index);
break;
}
}