Reputation: 742
I build a quick pagination from scratch it kind of works, but for the past half hour I've been trying to get the next and/or previous button to disable at the last page like this: (this one is for the next button)
if (currentPage.is(':last-child'))
{
$('.paj_next').prop('disabled', true);
$('.paj_previous').prop('disabled', false);
}
here is my code so you can try it out and see what's wrong for yourself:
When you click next it will go too far and not come back
Not exactly sure what's wrong, thanks a bunch in advance. JSFiddle scrambled up my code when I copied it in, sorry for it being so messy!
-Mike
Upvotes: 2
Views: 3344
Reputation: 150253
Problem:
var currentPage = $('.three_paj_els:visible');
Doesn't select a thing when you ran out of things to show.
Upvotes: 2
Reputation: 381
You have to check whether the nextPage is the last child, than it works: http://jsfiddle.net/Utr6v/36/
//-------------------------------------NEXT BUTTON
$('.paj_next').click(function() {
var currentPage = $('.three_paj_els:visible');
var nextPage = currentPage.next('.three_paj_els');
if (nextPage.is(':last-child')) {
$('.paj_next').prop('disabled', true);
$('.paj_previous').prop('disabled', false);
}
else {
$('.paj_next').prop('disabled', false);
$('.paj_previous').prop('disabled', false);
}
currentPage.hide();
nextPage.show();
});
Upvotes: 3