I have separate elements on my DOM with ID of "inner_1" up to "inner_20" e.g. inner_1, inner_2, inner_3, ect..
I made a javascript loop that will create separate event listeners functions to target each element, but it's assigning the wrong value to each function.
My loop in my .js file
for (section = 1; section < 21; section++) {
$('#inner_'+section).click(function(event) {
alert('Hooray!'+section);
event.preventDefault();
});
};
It outputs
=> "Hooray!21"
For every element I click on, regardless if it's "inner_1" or "inner_15".
How can I make it display the correct number for every function made e.g. "inner_14" will have alert of "14"
Thank you!