0

I'm a beginner in jQuery and I tried to make a pagination with next, previous, first, and last button, but I cannot.

This is my code:

pageSize = 8; var pageCount = $(".group").length / pageSize; for(var i = 0 ; i<pageCount;i++){ $("#pagin").append('<li><a href="#">'+(i+1)+'</a></li> '); } $("#pagin li").first().find("a").addClass("current") showPage = function(page) { $(".group").hide(); $(".group").each(function(n) { if (n >= pageSize * (page - 1) && n < pageSize * page) $(this).show(); }); } showPage(1); $("#pagin li a").click(function() { $("#pagin li a").removeClass("current"); $(this).addClass("current"); showPage(parseInt($(this).text())) }); 
2
  • What is your question? Commented Jun 11, 2018 at 15:40
  • If you are a beginner in jQuery you should use a plugin. The fact that you cannot express the details of your problem except for "I cannot" , means that you need help in fundamental knowledge, "cut and paste" is not programming. Commented Jun 22, 2018 at 3:28

1 Answer 1

1

It's not very clear what you're looking for, but I'm guessing you want next/previous links in your pagination links.

First is very simple - just link to the page with index 0:

$("#pagin").append('<li><a href="#" class="hidden" data-index="0">first</a></li>'); 

likewise last is just a link to the page count:

$("#pagin").append('<li><a href="#" class="hidden" data-index="'+pageCount+'">last</a></li>'); 

prev/next pages will need you to store what the current page is:

https://jsfiddle.net/cfqx3ba6/

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. Sorry, I didn't explain well enough.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.