2

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:

http://jsfiddle.net/Utr6v/25/

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

user1053263
  • 722
  • 2
  • 16
  • 33
  • 1
    Problem: `var currentPage = $('.three_paj_els:visible');` Doesn't select a thing when you ran out of things to show. Fix it in the manner suits you. – gdoron Mar 18 '12 at 10:01
  • OHHH! I fixed it really easily ahaha http://jsfiddle.net/Utr6v/34/ – user1053263 Mar 18 '12 at 10:05
  • @gdoron can you please reply to this as an answer so I can accept the answer? Your comment helped realize my mistake. – user1053263 Mar 18 '12 at 10:07

2 Answers2

3

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();



});
Simon
  • 371
  • 2
  • 11
2

Problem:

var currentPage = $('.three_paj_els:visible');

Doesn't select a thing when you ran out of things to show.

gdoron
  • 147,333
  • 58
  • 291
  • 367