I'm trying to use .addEventListener inside a loop with arrays (if that's at all possible) for use with multiple audio players on the same webpage. The audio players are just standard HTML5 audio but with custom controls.
This is just some test code to explain:
array[0].addEventListener('click',function() {
array[0].play();
});
array[1].addEventListener('click',function() {
array[1].play();
});
How would I be able to condense rather than writing this out for every value of the array? I've already tried putting it inside a (for) loop but then it just appeared to ignore it altogether:
For (i = 0; i < array.length; i++) {
array[i].addEventListener('click',function() {
array[i].play();
});
}
Apologies in advance if I'm being an idiot and/or missing something obvious.