Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple jQuery Pagination

I have a page with about 50 divs on it. I would like to organise these divs into groups of six, so that the client doesn't get 'information overload'. I have created a simple example/reduced test case of my problem. As you can see, there a lots of divs, and I want it so that when the page loads, only the first six are visible, but when you click on page 2 or next, the next six are revealed et cetera. The class of the page number you are on should also be set to have class="current".

So far I have tried using jQuery, but I have been getting quite stuck! Any help would be much appreciated!

like image 555
jacktheripper Avatar asked Nov 27 '22 14:11

jacktheripper


1 Answers

When a page is requested, hide all content divs, then iterate through them and show those that should appear on the "page":

showPage = function(page) {
    $(".content").hide();
    $(".content").each(function(n) {
        if (n >= pageSize * (page - 1) && n < pageSize * page)
            $(this).show();
    });        
}

http://jsfiddle.net/jfm9y/184/

like image 139
georg Avatar answered Dec 06 '22 02:12

georg