0

I have a bunch of previous and next buttons on more multiple mobile carousels on the same page, and I'd like to assign event handlers to the previous and next buttons of each carousel for when they're touched. However, chrome's mobile emulator doesn't respond to any touches, and I think it may be a problem with passing the value of i into my handlers.

for (let i = 0; i < number_of_carousels; i++){
    prev_button_list[i].addEventListener("touchend", handleMoveToPrevSlide(i));
    next_button_list[i].addEventListener("touchend", handleMoveToNextSlide(i));
}

Also, I got the lists of elements with the following:

prev_button_list = document.getElementsByClassName("carousel-prev");
next_button_list = document.getElementsByClassName("carousel-next");

Maybe I'm missing something?

pseudosudo
  • 23
  • 5
  • real question is, why do you need to know the index of the element in those functions - since those lists are live lists, do you ever add/remove elements with those classes? If you do, then the index won't mean a thing – Bravo Mar 20 '22 at 03:32
  • by the way, the reason your code fails is because you aren't passing a function reference to addEventListener, your passing the result of calling that function - so, that function is run immediately and never again – Bravo Mar 20 '22 at 03:39

0 Answers0