jQuery Pagination

by Alvin Olavarrieta

HTML

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.1/css/bootstrap.min.css">
<ul class="pagination"> </ul>

JavaScript

$(function(){
    var limit = 10;
    var startPage = 1;
    var endPage = 10;
    var currentPage = 0;
    console.log('limit ' + limit);
    console.log('startPage ' + startPage);
    console.log('endPage ' + endPage);
    console.log('currentPage ' + currentPage);
    
    var html = '';
    
    // if we are not at the first page, show the "Prev" button
    if (currentPage > 1) {
        html += '<li><a href="javascript:previous();">Prev</a></li>';
    }
    
    while(limit > currentPage){
        html += '<li><a href="javascript:go_to_page(' + endPage * currentPage +');">'+ (currentPage + 1) +'</a></li>';
        currentPage++;
    }
    
    html += '<li><a href="javascript:go_to_page(' + endPage * limit +');">Next</a></li>';
    
    $('.pagination').append(html);
    
});