I am using following code to implement pagination functionality. All items are rendering on page load and li elements greater than page set are hidden with CSS.

I want to make this code reusable so that any static pagination in my project can use this snippet with dynamic parameters.

var countShown = $('ul li').not('.hidden').length;
$('.load-more').on('click', function(){    
    var countHidden = $('ul li.hidden');
    for(var i=0; i < countShown; i++) {

JS Fiddle

Please help me with suggestions to improve above written code.

  • 1
    \$\begingroup\$ Hello there and welcome to codereview. Unfortunately your question doesn't match what this site is about. We do not provide assistance in changing what your code does, but review the current state of the code and suggest improvements. For more information, please refer to the help center \$\endgroup\$ – Vogel612 Apr 15 '15 at 12:59
  • \$\begingroup\$ @Vogel612 - Thanks for the feedback. I have edited the post for suggestions to optimize the code. I hope this works. \$\endgroup\$ – pradeep Apr 15 '15 at 13:15
  • \$\begingroup\$ @pradeep It still sounds slightly off-topic. I'm not voting to close, but you might want to edit the question a bit more. Currently it still sounds a bit like a do-the-coding-for-me question; you already know what's bad about the code (it's not reusable), you just don't know how to change it/didn't change it yet. \$\endgroup\$ – tim Apr 15 '15 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.