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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:25:27+00:00 2026-06-07T09:25:27+00:00

I’m trying to prevent Jquery Mobile initialization until after the page content has been

  • 0

I’m trying to prevent Jquery Mobile initialization until after the page content has been loaded, but I’m not getting the desired result. The project is a simple Question/Answer quiz. In my HTML document I have 3 containers div[data-role=page]:

div[data-role=page]#pg_title
div[data-role=page]#q0
div[data-role=page]#result

My document.ready() parses an external JSON file to load the content to these pages, duplicated #q0 to the number of questions in the quiz. The end result is something like:

div[data-role=page]#pg_title
div[data-role=page]#q0
div[data-role=page]#q1
div[data-role=page]#q2
div[data-role=page]#q3
div[data-role=page]#q4
div[data-role=page]#result

In my document head, I have:

<script>
    $(document).bind("mobileinit", function () {
        $.mobile.autoInitializePage = false;
    });
</script>
<script src="js/quiz.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script> 

http://jquerymobile.com/demos/1.1.0/docs/api/globalconfig.html says to configure settings before Jquery Mobile is loaded, which I had done. At the end of quiz.js I have the call to initialize the page:

$(document).ready(function(){

    // ... all the code to load JSON quiz content is here

    $.mobile.initializePage();
}); 

My problem is that when I proceed from the title page to the first question page, I see all of the questions rending at the same time. The rendered HTML looks like this:

<div data-role="page" id="q0" class="pg_type_question ui-page ui-body-c ui-page-active" data-title="Quiz Title" data-url="q0" tabindex="0" style="min-height: 826px; ">...</div>
<div data-role="page" id="q1" class="pg_type_question ui-page ui-body-c ui-page-active" data-title="Quiz Title" data-url="q0" tabindex="0" style="min-height: 826px; ">...</div>
<div data-role="page" id="q2" class="pg_type_question ui-page ui-body-c ui-page-active" data-title="Quiz Title" data-url="q0" tabindex="0" style="min-height: 826px; ">...</div>
<div data-role="page" id="q3" class="pg_type_question ui-page ui-body-c ui-page-active" data-title="Quiz Title" data-url="q0" tabindex="0" style="min-height: 826px; ">...</div>
<div data-role="page" id="q4" class="pg_type_question ui-page ui-body-c ui-page-active" data-title="Quiz Title" data-url="q0" tabindex="0" style="min-height: 826px; ">...</div>

After document.ready() but before mobile.initializePage is called the HTML renders as:

<div data-role="page" id="q1" class="pg_type_question" data-title="Quiz Title">...</div>
<div data-role="page" id="q2" class="pg_type_question" data-title="Quiz Title">...</div>
<div data-role="page" id="q3" class="pg_type_question" data-title="Quiz Title">...</div>
<div data-role="page" id="q4" class="pg_type_question" data-title="Quiz Title">...</div>
<div data-role="page" id="q5" class="pg_type_question" data-title="Quiz Title">...</div>

I don’t understand why every question page is becoming active with a data-url of “q0”.

Thanks in advance for your help!

  • 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-07T09:25:31+00:00Added an answer on June 7, 2026 at 9:25 am

    It’s a little hard to say without seeing the full page. Here’s an example I put together of what you describe. autoInitializePage is set to false (before jQuery Mobile gets loaded), some elements get added to the DOM after the page is loaded, and then $.mobile.initializePage(); is called once we’re done fiddling with the page. jQuery Mobile then initializes it as expected and the navigation links seem to work.

    <html> 
      <head>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
        <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
        <script type="text/javascript">
            $(document).bind("mobileinit", function () {
                $.mobile.autoInitializePage = false;
            });
        </script>
        <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                $('body').append(
                    '<div data-role="page" id="q1" class="pg_type_question" data-title="Quiz Title">' +
                        '<div data-role="header">' +
                            '<h1>Page 1</h1>' +
                        '</div>' +
                        '<div data-role="content">' +
                            '<h2>Content</h2>' +
                            '<p><a href="#q2" data-role="button">To Page 2</a></p>' +
                        '</div>' +
                    '</div>' +
                    '<div data-role="page" id="q2" class="pg_type_question" data-title="Quiz Title">' +
                        '<div data-role="header">' +
                            '<h1>Page 2</h1>' +
                        '</div>' +
                        '<div data-role="content">  ' +
                            '<h2>Content</h2>' +
                            '<p><a href="#q3" data-role="button">To Page 3</a></p>  ' +
                        '</div> ' +
                    '</div>' +
                    '<div data-role="page" id="q3" class="pg_type_question" data-title="Quiz Title">' +
                        '<div data-role="header">' +
                            '<h1>Page 3</h1>' +
                        '</div>' +
                        '<div data-role="content">' +
                            '<h2>The End</h2>' +
                        '</div>' +
                    '</div>'
                );
    
                $.mobile.initializePage();
            });
        </script>
      </head> 
      <body>
        <div data-role="page" id="title" data-title="Quiz Title">
            <div data-role="header">
                <h1>Title Page</h1>
            </div>
            <div data-role="content">
                <h2>Welcome</h2>
                <p><a href="#q1" data-role="button">To Page 1</a></p>
            </div>
        </div>
      </body>
    </html>
    

    While playing around, I did note that the [div data-role="page"] elements really do need to be siblings of one another; check to make sure that you’re not accidentally appending them all to the title page or to a parent element other than the body.

    If you’re calling to an external JSON source, you’ll want to make sure that the call to $.mobile.initializePage(); is handled in the completion callback; otherwise, you may end up with a race condition in which $.mobile.initializePage(); is called before the AJAX call to the JSON source is completed.

    Hope this helps!

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of 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.