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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:57:58+00:00 2026-06-05T07:57:58+00:00

As Jquery Mobile keeps some pages in the DOM when navigating around, a page

  • 0

As Jquery Mobile keeps some pages in the DOM when navigating around, a page may be visited multiple times when going back and forth.

If I’m binding to a page like below and inside this binding perform all my page logic, which includes “nested element bindings”:

// listener for the page to show:
$(document).on('pagebeforeshow.register', '#register', function() {

    // stuff

    // page event bindings:
    $(document).on('click.register', '.registerSubmitter', function(e) {
        // do something
        });
    });

Going back and forth causes my nested binding to be attached multiple times.

Right now trying to work around this like so (doesn’t work…):

 $(document).on('click', '.registrySubmitter', function(e) {

         if ( $(this).attr('val') != true ) {
            $(this).attr('val') == true;
            // do something
            }
     });

So I’m only allowing the first binding to pass and then I block every other binding attempt that comes along.

While this works, it’s far from optimal.

Question:
How and when should event bindings be properly unbound/offed? Is there a general way (kill all) or do I have to do this binding per binding? Maybe more importantly: Is it better performance-wise to do a binding once and keep it or bind/unbind when the user comes to/leaves the page?

Thanks for input!

EDIT:
So I’m namespacing all my events and then listen for pageHide like so:

$(document).on('pagehide.register', '#register', function(){
   $(document).off('.registryEvents');
   });

While this seems to unbind, it also fires when ever I close a custom dialog/selectmenu on the page, so I’m loosing my bindings before leaving the page. So partial answer, I should use off(), but how to bind to the page really being left vs. opening and closing a select menu?

  • 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-05T07:57:59+00:00Added an answer on June 5, 2026 at 7:57 am

    When you use .on() like that, you are delegating the event handling to the document element, meaning you can setup that delegated event binding anytime you want because the document element is always available.

    I’ve got two suggestions:

    • Use the pageinit or pagecreate event to only run the page-specific bindings when pages are added to the DOM and initialized. Using this method I would not delegate the event bindings within the pageinit or pagecreate event handlers because when they fire, all the elements on the pseudo-page are in the DOM:

    .

    $(document).on('pageinit', '#register', function() {
        //note that `this` refers to the `#register` element
        $(this).find('.registerSubmitter').on('click', function(e) {
            // do something
        });
    });
    
    • Bind the delegated event handlers once and don’t worry about when pages are actually in the DOM:

    .

    //this can be run in the global scope
    $(document).on('click.register', '.registerSubmitter', function(e) {
        // do something
    });
    

    Basically when you bind an event using delegation like you are, the actual CPU hit of adding the event handler is less but each time an event is dispatched (of any kind that bubbles) it has to be checked if it matches the delegated event handler’s selector.

    When you bind directly to elements it generally takes more time to do the actual binding because each individual element has to be bound to rather than binding once to the document element like with event delegation. This however has the benefit that no code runs unless a specific element receives a specific event.

    A quick blurb from the documentation:

    Triggered on the page being initialized, after initialization occurs.
    We recommend binding to this event instead of DOM ready() because this
    will work regardless of whether the page is loaded directly or if the
    content is pulled into another page as part of the Ajax navigation
    system.

    Source: http://jquerymobile.com/demos/1.1.0/docs/api/events.html

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

Sidebar

Related Questions

In JQuery Mobile I am using changePage() to redirect back to a previous page,
I have a Jquery Mobile page. In my header I have a button to
I am using jquery mobile. I would like to navigate from one page to
I find that JQuery Mobile pages look good on MDPI devices (like G1) but
jQuery mobile 1.0 I change the content of the page, to put it simple:
Note: I'm using jQuery and jQuery Mobile. I have a mobile page which seems
I'm using jQuery Mobile and trying to figure out how to change a page
With jQuery mobile I'm using a dynamic 'page' template with custom content inserted depending
I am looking for a way to produce the jQuery mobile horizontal page transition
I have a link that create a dialog with jquery mobile in my page

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.