0

I have problem with getting innerHTML value from element in "for" loop. This is my code:

for (i; i<count; i++) {
document.getElementsByClassName("element")[i].addEventListener("click", function() {
    quantity = document.getElementsByClassName("quantity")[i].innerHTML;
    console.log(quantity);
});r
}

Loop is working correctly but I can't get innerHTML value from clicked object.

EDIT: I have tried to do something like this:

for (i; i<count; i++) {
 document.getElementsByClassName("dodaj_do_koszyka")[i].addEventListener("click", function(e) {
    e.preventDefault();
    // dodaj(i);
    console.log(i);
});
}
function dodaj(i) {
 var quantity = document.getElementsByClassName("quantity")[i].innerHTML;
 console.log(quantity);
}

Still doesn't work. i from for loop shows me numbers(iterations?) of i, not the value.

Damian Hetman
  • 372
  • 4
  • 20

0 Answers0