I have two event listeners and I have a counter. When I click the element, I always get the last number of the counter.
How can I get or pass the correct counter.
let i = 0;
document.querySelectorAll('div').forEach(element => {
element.addEventListener("click", () => {
console.log(i);
})
i++;
});
<div>
Click me
</div>
<div>
Click me too
</div>