i need help for this script.
I would like the global variable to be updated when an element of the array is clicked. But this doesn’t work and I can’t find the way.
const img = document.querySelectorAll("#img");
let imgPos = 1;
img.forEach((element) => {
element.addEventListener("click", () => {
carousel.style.visibility = "visible";
imgPos = parseInt(element.dataset.counter);
return imgPos;
});
carouselSlide.style.transform = "translateX(" + -size * imgPos + "px)";
in the final string the value of ImgPos remains at 1.
Thanks
I expect the value of ImgPos to change every time the array event executes.