0

I want to make pagination with jquery and Ajax. The first where I'm stumbling on is how I can add a button

<div class="btn-group" id="pagination_group">
        <button class="btn" disabled="disabled">First</button>
        <button class="btn" disabled="disabled">Prev</button>
        <button class="btn btn-primary" id="p1">1</button>
        <button class="btn" id="p2">2</button>
        <button class="btn" id="p3">3</button>
        <button class="btn" id="p4">4</button>
        <button class="btn" id="p5">5</button>
        <button class="btn" id="next">Next</button>
        <button class="btn" id="last">Last</button>
    </div>

Something with append()? But how to get it it the right place? The idea is after click on Next remove btn with id="p1" ( that's no problem) and add button with id="p6" between button5 and button Next.

Thank you for your advice.

2 Answers 2

2
$("#next").click(function(){
    $("#p1").remove();
    $("#next").before($('<button class="btn" id="p6">6</button>'));
})
Sign up to request clarification or add additional context in comments.

2 Comments

I think you may remove the button that is after prev-button, because there won't be a "#p1" element for second time of clicking next button.
yeah, but I just answered wat was exectly asked for..I know this is not gonna work in general..cuz in that case he needs to change p6 and p1 info with preper variables..
0

Possibly several ways to accomplish this. See this working example

1 Comment

Thank you. It is complete solution (at least what I nedeed for the moment).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.