Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9240759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:14:45+00:00 2026-06-18T08:14:45+00:00

At the moment I’m using a pager that when you click the page numbers

  • 0

At the moment I’m using a pager that when you click the page numbers loads the page. At the moment the code displays the current 10 closest pages and then arrows to go first, previous, next and to the last pages.

My aim is to create jQuery to dynamically update the #pages div with the correct numbers and/or remove the arrows if the user is on the first or last page.

HTML

<div id="pages">
    <a href="1" class="first">&laquo;</a>
    <a href="1" class="previous">&lsaquo;</a>    
    <span class="current">2</span>  
    <a href="3">3</a>
    <a href="4">4</a>
    <a href="5">5</a>
    <a href="6">6</a>
    <a href="7">7</a>
    <a href="8">8</a>
    <a href="9">9</a>
    <a href="10">10</a>
    <a href="11">11</a>   
    <a href="3" class="next">&rsaquo;</a>
    <a href="128" class="last">&raquo;</a>
</div>

Example jQuery for highest number click

//change page numbers if highest number clicked
$(document).on("click", "#pages a", function(){
    if($(this).index() == 11){
        $("#pages :nth-child(3)").remove();
        $("#pages a:nth-child(11)").after('<a href="'+ (parseInt($(this).text()) + 1) + '" rel="nofollow" class="current">'+ (parseInt($(this).text()) + 1) + '</a>');
    }
});

Here’s a jFiddle with a working example of what I currently have:

http://jsfiddle.net/84NaC/5/

You can see in the jFiddle example that if you click the lower arrow or lowest number then the lowest number is removed and a new high number is inserted. The comments explain how this bit works.

The Problem

The current approach is kind of buggy and I’m not very happy with how it functions, is there a more reliable way to do what I’m looking for?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:14:46+00:00Added an answer on June 18, 2026 at 8:14 am

    I played with your JSFiddle and modified the HTML to

    <div id="content">Default</div>
    <div id="pages">
        <a href="1" class="goto-first-page">&laquo;</a>
        <a href="#" class="goto-previous-page">&lsaquo;</a>
        <a href="1" class="goto-page">1</a>
        <a href="2" class="goto-page current-page">2</a>
        <a href="3" class="goto-page">3</a>
        <a href="4" class="goto-page">4</a>
        <a href="5" class="goto-page">5</a>
        <a href="6" class="goto-page">6</a>
        <a href="7" class="goto-page">7</a>
        <a href="8" class="goto-page">8</a>
        <a href="9" class="goto-page">9</a>
        <a href="10" class="goto-page">10</a>
        <a href="11" class="goto-page">11</a>
        <a href="#" class="goto-next-page">&rsaquo;</a>
        <a href="128" class="goto-last-page">&raquo;</a>
    </div>
    

    defined some functions

    function update_page_content(n)
    {
        $('#content').html('Page ' + n + ' Content');
    }
    
    function update_page_range(lower_bound)
    {
        var range = range_last_page - range_first_page;
        range_first_page = lower_bound;
        range_last_page = lower_bound + range;
        $('.goto-page').each(function(index) {
            $(this).attr('href', lower_bound + index).text(lower_bound + index);
        });
    
    }
    
    function goto_page(n) {
        // adjust current page
        var current = $('.goto-page[href="' + n + '"]');
        if (current.length == 0) {
            if (n <  range_first_page) {
                if (n >= first_page) {
                    var lower_bound = Math.max(first_page, n - 5);
                    update_page_range(lower_bound);
                    current = $('.goto-page[href="' + n + '"]');
                }
            } else if (n > range_last_page) {
                if (n <= last_page) {
                    var upper_bound = Math.min(last_page, n + 5);
                    update_page_range(upper_bound - 10);
                    current = $('.goto-page[href="' + n + '"]');
                }
            }
        }
    
        if (current.length > 0) {
            // set content
            update_page_content(n);
    
            $('.goto-page').removeClass('current-page');
            current.addClass('current-page');
        }
    }
    

    and then set the click()s individually

    $('.goto-previous-page').click(function () {
        var n = $('.current-page').attr('href');
        goto_page(+n - 1);
        return false;
    });
    $('.goto-next-page').click(function () {
        var n = $('.current-page').attr('href');
        goto_page(+n + 1);
        return false;
    });
    $('.goto-first-page, .goto-last-page, .goto-page').click(function () {
        var n = $(this).attr('href');
        goto_page(+n);
        return false;
    });
    

    Complete JSFiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the moment I'm using this code /usr/libexec/PlistBuddy -c Set PreferenceSpecifiers:1:DefaultValue $productVersion Test/Settings.bundle/Root.plist in
At the moment I have some test code that starts something like this: CheckBoxPreference
At the moment I am generating a barcode using Shay Anderson's class (http://www.shayanderson.com/php/php-barcode-generator-class-code-39.htm) and
At the moment I'm using this code if __name__==__main__: try: main() except KeyboardInterrupt: f.close
At the moment, I am generating xml and json data using the following code:
At the moment I am using the following bit of code to only get
At the moment I have a page that outputs a bunch of records held
At moment I want to implement picture upload without using any plug-ins. My upload
There is a moment in my app, that I need to force to show
At the moment I'm using bat file to launch my jar and set the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.