i'm trying to loop an HTMLCollection and i want to add a onclick event inside each element.
for(var page of pages){
page.onclick = () => {
console.log(count)
}
count += 1
}
Well, the problem is actually that when i click the button, it shows up only the last counted number (5), but not actually the counted element. How to fix it? Thanks.