Ad multiple Buttons to event listener
Hello
I was wondering if it's possible to add multiple buttons to an event listener with a for loop? I have looked for similar solutions but don't think I quite understand them...
Essentially I have a number of buttons with consecutive instance names (e.g. but1, but2, but3 etc.) and want to assign them all to the same event listener. Something like:
for (i=1; i<5; i++) {
this.but[i].addEventListener("click", fl_MouseClickHandler.bind(this));
}
I have two arrays lined up to match this numbering and it would be great if I could return the entries from those arrays once the relevant button is clicked on also. Something like:
function fl_MouseClickHandler(e)
{
for(i = 1; i < 5; i++){
if(e.currentTarget.name == but[i]){
var myVal = this.myArray[i]; //pull my array values
}
}
Hope that makes sense!
Thanks
}
