As a beginner in JQuery, I am trying to achieve a functionality where an image displayed on a website can be selected on mouse click, and a popup slider containing that image is shown.
I have managed to make it work, but when clicking "next" in the slider, it always starts from the first image instead of showing the next one.
Here is my code:
var currentPosition = 0;
$('#btnNext').click(function() {
// Copying the selected image to the placeholder
$('#mimg').attr('src', $('.images .display').eq(currentPosition).attr('src'));
currentPosition++;
if(currentPosition == $('.images .display').length) {
currentPosition = 0;
}
});
Issue: When clicking "Safari", it should display the next image, but it always shows "Firefox" (the first one).
Can anyone provide assistance with this problem?