var numberOfItems = $('#custom-pagination-container .custom-pagination-page').length; var limitPerPage = 5; console.log('Items: ' + numberOfItems); $("#custom-pagination-container .custom-pagination-page:gt(" + (limitPerPage -1) + ")").hide(); var totalPages = Math.round(numberOfItems / limitPerPage); $('.pagination').append("
  • " + 1 + "
  • "); for (var i = 2; i <= totalPages; i++) { $('.pagination').append("
  • " + i + "
  • "); } $('.pagination').append("
  • Next
  • "); $(".pagination li.custom-pagination-current-page").on("click", function () { if ($(this).hasClass("active")) { return false; } else { var currentPage = $(this).index(); console.log('Index: ' + currentPage); $(".pagination li").removeClass("active"); //$(this).addClass("active"); //$(".pagination li.custom-pagination-current-page:eq(" + (currentPage-1) + ")").addClass("active"); $("#pagingTop li.custom-pagination-current-page:eq(" + (currentPage-1) + ")").addClass("active"); $("#pagingBottom li.custom-pagination-current-page:eq(" + (currentPage-1) + ")").addClass("active"); $(".custom-pagination-page").hide(); var grandTotal = limitPerPage * currentPage; for ( var i = grandTotal - limitPerPage; i < grandTotal; i++) { $("#custom-pagination-container .custom-pagination-page:eq(" + i + ")").show(); } } }); $(".custom-pagination-next-page").on("click", function () { var currentPage = $(".pagination li.active").index(); if (currentPage === totalPages) { return false; } else { currentPage++; $(".pagination li").removeClass("active"); $("#custom-pagination-container .custom-pagination-page").hide(); var grandTotal = limitPerPage * currentPage; for ( var i = grandTotal - limitPerPage; i < grandTotal; i++) { $("#custom-pagination-container .custom-pagination-page:eq(" + i + ")").show(); } //$(".pagination li.custom-pagination-current-page:eq(" + (currentPage - 1) + ")").addClass("active"); $("#pagingTop li.custom-pagination-current-page:eq(" + (currentPage - 1) + ")").addClass("active"); $("#pagingBottom li.custom-pagination-current-page:eq(" + (currentPage - 1) + ")").addClass("active"); } }); $(".custom-pagination-previous-page").on("click", function () { var currentPage = $(".pagination li.active").index(); if (currentPage === 1) { return false; } else { currentPage--; $(".pagination li").removeClass("active"); $("#custom-pagination-container .custom-pagination-page").hide(); var grandTotal = limitPerPage * currentPage; for ( var i = grandTotal - limitPerPage; i < grandTotal; i++) { $("#custom-pagination-container .custom-pagination-page:eq(" + i + ")").show(); } //$(".pagination li.custom-pagination-current-page:eq(" + (currentPage - 1) + ")").addClass("active"); $("#pagingTop li.custom-pagination-current-page:eq(" + (currentPage - 1) + ")").addClass("active"); $("#pagingBottom li.custom-pagination-current-page:eq(" + (currentPage - 1) + ")").addClass("active"); } }); -->