0

I try to increase h4 which is count.innerHTML when click to button. There are 3 buttons, how can I manipulate them, and what is wrong with that code?

var btnInc = document.querySelectorAll(".inc");
var count = document.querySelectorAll(".count");

var num = 0;

for(var i=0; i<btnInc.length; i++) {
    btnInc[i].addEventListener('click', function(){
        count[i].innerHTML=num;
        num++;
    })
}

Kaderzone
  • 11
  • 5
  • could you please share HTML as well – PU_ Jun 06 '21 at 13:56
  • Wrap your code inside for loop in an IIFE and pass the btnInc[i], count[i] and num to that IIFE so that they have different values for different events binded on the elements. – Nandita Sharma Jun 06 '21 at 14:00

0 Answers0