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

  • Home
  • SEARCH
  • 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 8067955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:30:11+00:00 2026-06-05T12:30:11+00:00

There are two pages in my jQuery mobile application. When a list item on

  • 0

There are two pages in my jQuery mobile application. When a list item on the first page is tapped, the user is taken to the second html page. The second page has a navbar which has two buttons. I want these two navbar buttons to show/hide a div in the content area of the page. I couldn’t find which event handling mechanism to use. document.ready doesn’t work, pageinit doesn’t work also. Can someone direct me to a sample?

  • 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-05T12:30:13+00:00Added an answer on June 5, 2026 at 12:30 pm

    If you mean you have two (or more) separate HTML files you need to understand how to handle events properly in jQM, so here’s a quick intro.

    1. jQM adds even separate HTML files into a single DOM, thru loading them by AJAX

    2. Each page that is loaded via AJAX fires a pageinit and a pageshow event, difference being that pageshow re-fires when you navigate back to the page

    3. Every page after the first page only loads content within the <div data-role="page/dialog"></div> element, therefore if your subsequent pages have JS in the <head/> that is not pulled in perhaps you have your second page’s navbar JS code in your second page’s , this is a big thing to note

    4. So how do you manage your JS and keep it organized? In our production jQM app we load all our JS at the start, it’s not too big minified anyways. We have one entry point and the JS code is included on every page, so whichever page you enter from loads all the JS we need just once – and no more JS is loaded. Warning if you have JS within your <div data-role="page"/> it will refire everytime you visit the page only do this if you know how it acts

    5. Your entry point should be a single function $(document).on('pageinit pageshow', 'div:jqmData(role="page"), div:jqmData(role="dialog")', function(event){ now every page/dialog that loads will trigger this event handler, you can determine if it’s pageinit or pageshow based on event.type AND which page loaded by adding a data-attribute or class or anything you want to the <div data-role="page" data-pageIdentifier="home etc.."></div> – then just use a switch statement to handle for all the cases.

    6. You now have all the info you need and this is a handy reference to the current page, bind event listeners with the .on function, so you listen at the page, NOT the document root, e.g. your navbar stuff. – If you use .live it will listen for the entire document (not all pages are DOM cached though), regardless this is bad for performance! Actually within a page, we always use .find starting from the page, e.g. $this.find(‘div.something’), we never use $(‘div.something), that will crawl your entire DOM possibly hitting other pages AND worse giving you erroneous results not within your current page so another big mistake is to do something like $('img.selectItem').bind('click'... you may have an img.selectItem in another DOM cached page, so you’ll bind to more than you want to – I would do something like $this.find('img.selectItem').bind( (where $this is the current page)

    Obviously we had a lot of code eventually, so we wrote a handler object that called functions in other JS files – and you can use RequireJS but we never needed to

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

Sidebar

Related Questions

Lets say there are two pages with two different html elements which have the
In my html page, I have one table, for every row there are two
Page 146 of the jQuery mobile First look book mentions data-placeholder, but I don't
There are two accordions on my page, with custom accordion CSS in another file,
http://www.ericmmartin.com/projects/simplemodal/ There's two examples near the bottom of the page that show how to
There is a page on our server that's reachable via two different URLs. http://www.spotlight.com/6213-5613-0721
New question, but really close to need to refresh page in jquery mobile .
I have a single HTML page where I need to have three jqm pages
I have two lists displaying on a web page: (List of Clients) (List of
I have a page on which I'm using JQuery Mobile. I am having difficulty

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.