When I run this code, every time I click the '#right' button, the #slide increments by 2 instead of just 1. For example, if there are a total of 6 elements, it displays the 1st, 3rd, and 5th elements.
var currentSlide=2;
var totalSlides=document.getElementById("slider").childElementCount;
$("#right").click(function()
{
for(i=1;i<=totalSlides;i++) {
$("#slide"+i).css("display","none"); // hide all elements
}
$('#slide'+currentSlide).css("display","block"); // displaying only one element (which gets incremented by 2)
currentSlide=(currentSlide+1)%totalSlides;
});
If I use specific numbers like ('#slide'+2) instead of ('#slide'+currentSlide), I get the right results. However, I want to do this dynamically...
Thanks!