New to JavaScript? You’re going to face this issue if not already

Adding click event listeners in a loop can be a mystery

Raja Tamil
Level Up Coding
Published in
6 min readFeb 18, 2020

--

When you attach multiple click events to elements such as buttons inside a for loop, the click event will always give us the last index value regardless of what button is pressed.

--

--

👇click the link and get 80% OFF on the premium web development courses (HTML5, CSS3, JavaScript ES6, Vue JS 3 & Firebase 10 https://softauthor.com