Reputation:
I'm looping through a series of images, passing the class .current
along a series of elements, and cloning it each time. Like so:
Note: I'm using .img
as a placeholder for img
.
$('.next').click(function(){
$('.main-frame').empty();
if (!$('.slide-controller .slide.current').is(':last')) {
$('.current')
.removeClass('current')
.next()
.addClass('current')
.clone('.img')
.appendTo('.main-frame');
} else {
alert('else!'); // this is never called
}
});
Problem: The if statement does not seem to be working correctly: the else
is never called. Would anyone know why?
(Eventually, when the .current
is on the last child, I need to reverse the slideshow)
Upvotes: 1
Views: 129
Reputation: 21050
I think I answered this first in the comments above but no biggie if you accept someone else's answer first.
Change :last to :last-child
Upvotes: 1
Reputation: 7374
Change last
for last-child
and all should be well:
if (!$('.slide-controller .slide.current').is(':last-child')) {
Upvotes: 0
Reputation: 388316
You are not specifying last of what... try
$('.slide-controller .slide.current').is('.slide-controller .slide:last')
Demo: Fiddle
Or check for :last-child
$('.slide-controller .slide.current').is(':last-child')
Demo: Fiddle
Upvotes: 2