If i have a program that is adding and taking away html elements dynamically and each one of these elements needs to have an event listener is there a way to add the event listener to a variable that's easier than doing it one by one? I wanted to use an array and have each index of the array to have a event listener attached to it but that doesn't seem to work.
var1 = document.getElementById('name');
var1.addEventListener("mousedown", doMouseDown, false);
This works fine but i have about 100 elements so i was hoping there is an easier way than creating 100 individual variables. I there is an easier way to do this i would love any suggestions. :)