I am displaying a series of elements using the next() function. Once I reach the end though, I want to go to the first element. Any ideas?
Here's the code:
//Prev / Next Click
$('.nextSingle').click( function() {
//Get the height of the next element
var thisHeight = $(this).parent().parent().parent().next('.newsSingle').attr('rel');
//Hide the current element
$(this).parent().parent().parent()
.animate({
paddingBottom:'0px',
top:'48px',
height: '491px'
}, 300)
//Get the next element and slide it in
.next('.newsSingle')
.animate({
top:'539px',
height: thisHeight,
paddingBottom:'100px'
}, 300);
});
Basically I need an "if" statement that says "if there are no remaining 'next' elements, then find the first one.
Thanks!