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 8646647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:52:02+00:00 2026-06-12T12:52:02+00:00

I’ve written a custom paging scheme using jQuery 1.8.0. I’m binding event handlers to

  • 0

I’ve written a custom paging scheme using jQuery 1.8.0. I’m binding event handlers to the backwards and forwards buttons. To disable the backwards button when on page 1, I’m using the .off() function to disable the binding. When I page up, I call .on() on the button to enable the binding again. The problem occurs when I change the on/off state of an event binding three times. After that, the event won’t fire anymore.

A stripped down version of my code follows. This will illustrate my problem.

This is the event. The back button has the id of prevPageLink.

$("#prevPageLink").click( function() {
  // Decrement the current page
  global_currentPage--;

  // Check to see if first or last page clicked
  handlePaginationButtonState();

  // Decrement the results indicies
  startResultsIndex -= global_totalResultsPerPage;
  endResultsIndex = startResultsIndex + global_totalResultsPerPage - 1;

  getNextResults();  
});

The function handlePaginationButtonState does the work of turning on and off the back and forward buttons.

function handlePaginationButtonState() {

  if (global_currentPage == 1) {
    $("#prevPageLink").parent().attr('class', 'disabled');
    $("#prevPageLink").off('click');
  } else {
    $("#prevPageLink").parent().attr('class', 'enabled');
    $("#prevPageLink").on('click');
  }  // the rest of this function takes care of the numbered and right page buttons

So when the web app first brings results back, the first 10 results are loaded. If I do the following:

  1. Page next (to page 2) – binding turned on
  2. Page previous (back to page 1) – binding turned off
  3. Page next (to page 2) – biding turned on

I cannot page previous, back to page 1. The prePageLink button no longer responds. I have tested this with the next page button and the end of the results list as well as the numbered page buttons. If a binding has been turned on or off using the .on() or .off() functions, it no longer responds to events.

Any ideas? I am completely baffled.

  • 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-12T12:52:04+00:00Added an answer on June 12, 2026 at 12:52 pm

    ” If a binding has been turned on or off using the .on() or .off() functions”

    $("#prevPageLink").on('click') doesn’t do what you seem to think it does, in fact it doesn’t do anything at all because you didn’t supply enough parameters. The .on() method doesn’t turn on a previously removed event handler, it binds a new event handler and so you have to supply the function that will be called when the event happens. In other words:

    $("#prevPageLink").on('click', function() { /* some code */ });
    /// does the same thing as:
    $("#prevPageLink").click(function() { /* some code */ });
    

    The .off() method removes a previously bound handler, it doesn’t temporarily disable it.

    If you want to keep re-binding the same function don’t use an anonymous function:

    function myClickHandler() {
        // your code here
    }
    $("#prevPageLink").on('click', myClickHandler);
    // remove it:
    $("#prevPageLink").off('click');
    // add it again:
    $("#prevPageLink").on('click', myClickHandler);
    

    For more information read the .on() documentation.

    But rather than removing and rebinding handlers I think it would be easier to just leave the handler in place all of the time and have it test whether or not you’re already on the first page – add something like this to the beginning of the function:

    if (global_currentPage === 1)
       return false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to

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.