I am making a mini gallery where I can display my artworks. What I wanted to happen is that everytime I should click the "right" button image up until to the last photo, it will still repeat the images from the start. I tried the if statement but nothing happens. A little help will be much appreciated, thank you!
$(function(){
var currIndex;
//$("#header").hide();
$("ul li img").click(function() {
currIndex = $(this).parent();
var selectsrc = $(this).attr("src");
$("#display").attr("src", selectsrc);
$("#gray").slideDown();
$("#white").fadeIn();
});
$("#gray").click(function(){
$("#gray").slideToggle();
$("#white").fadeOut();
});
$("#right").click(function(){
var numOfItems = $("ul li img").length;
var nextIndex = currIndex.next();
var nextImg = nextIndex.children("img").attr("src");
$("#display").attr("src", nextImg);
currIndex = nextIndex;
if (currIndex == numOfItems-1){
alert("HELLO");
currIndex = 0;
}
else {
alert("HI");
currIndex++;
}
})
});