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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:23:43+00:00 2026-05-23T00:23:43+00:00

I have a page in JQuery mobile, which contains a form. The form has

  • 0

I have a page in JQuery mobile, which contains a form. The form has both static elements (defined in the html) and dynamic elements (created through script at runtime). The first time I go to my page, it renders correctly, with the JQuery mobile formatting. If I go back, then open the form again, all formatting of dynamic elements is lost. I have to reload the page to get my elements looking correct again.

My suspicion is that the DOM is being messed up somehow. I’m calling empty() on the parent element holding the dymanic content, so there shouldn’t be duplicate elements in the DOM.

Have reproduced this on both Chrome (windows) and the Andriod 2.3 browser.

Below is a simplified version of what I’m doing. In the real application, the elements come from a database, so most form views may contain different elements. Hence, they need to be re-created each time.

To see the behavior,

  1. click the “Show form” link,
  2. click the back button,
  3. then click the “Show form” link again. You will notice the formatting is gone.

Any ideas would be greatly appreciated

Fiddle: http://jsfiddle.net/tj4yF/1/

Code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <meta content=" initial-scale=1.0; maximum-scale=1.0;user-scalable=0;" />
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
             <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" />
                <script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
                <script src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>

                <script>
                    var g_aElementList = [];
                        g_aElementList.push( "<label for='ta'>General comment</label><textarea name='ta' id='ta' rows='3'></textarea>" );
                        g_aElementList.push( "<label for='num'>My Number</label><input type='number' name='num' id='num'/>");
                        g_aElementList.push( "<label for='chk'>My Checkbox</label><input type='checkbox' name='chk' id='chk' value='true'/>");

                    $("#pnlPage2").live("pagebeforeshow", function(event, ui) {

                        var jContainer = $("#elementContainer");

                        for( var cI=0; cI<g_aElementList.length; cI++ ) {
                            jContainer.append( "<li data-role='fieldcontain'>" + g_aElementList[cI] + "</li>" );    
                        }

                        jContainer.page();


                    });

                    $("#pnlPage2").live("pagehide", function(event, ui) {
                        $("#elementContainer").empty();
                    });

                </script>
        </head>
        <body>
            <div data-role="page" id="pnlPage1">
                <div data-role="header"> 
                  <h1>Page1</h1> 
                </div>
                <div data-role="content">
                    <a id="pnlTest" class="panel" href="#pnlPage2">Show form</a>
                </div>
                <div data-role="footer"> 
               </div>
            </div>
             <div data-role="page" id="pnlPage2">
                <div data-role="header"> 
                  <h1>Page2</h1> 
                </div>
                <div data-role="content">
                    <form id="frmTest">
                        <ul data-role="listview" data-inset="true" data-theme="c">
                            <div id="elementContainer"></div>
                        </ul>   
                    </form>
                </div>
                <div data-role="footer"> 
               </div>
            </div> 

        </body>
    </html>
  • 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-05-23T00:23:44+00:00Added an answer on May 23, 2026 at 12:23 am

    Not sure what’s going wrong. But I do feel that perhaps deleting and adding new dom elements is not really nescesairy. Also you may place everything in the document.ready wrapper to prevent errors.

    Somehow there’s a problem with #elementContainer being emptied. A workaround is do dynamically create it and afterwards delete it.

    Edit: Now it should be working without the hide/show

    Fiddle:
    http://jsfiddle.net/kkyWg/1/

    Code:

    $(document).ready(function () {
        var g_aElementList = [];
        g_aElementList.push( "<label for='ta'>General comment</label><textarea name='ta' id='ta' rows='3'></textarea>" );
        g_aElementList.push( "<label for='num'>My Number</label><input type='number' name='num' id='num'/>");
        g_aElementList.push( "<label for='chk'>My Checkbox</label><input type='checkbox' name='chk' id='chk' value='true'/>");
    
    
    
        $("#pnlPage2").live("pagebeforeshow", function(event, ui) {
            $('<div id="elementContainer"></div>').appendTo("#list");
    
            var jContainer = $("#elementContainer");
            for( var cI=0; cI<g_aElementList.length; cI++ ) {
                jContainer.append( "<li data-role='fieldcontain'>" + g_aElementList[cI] + "</li>" );
            }
            jContainer.page();
    
        });
    
        $("#pnlPage2").live("pagehide", function(event, ui) {
            $("#elementContainer").remove();
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page which contains a jQuery-UI horizontal slider, created using a little
I have created a web page using JQuery Mobile that has a link at
I have a login page using jQuery Mobile which contains the following code: <div
I have created a list in jquery mobile which directs to some page on
I'm using Jquery mobile framework. I have 2 html files which has two buttons
I have a single page jquery mobile application in which there are few parent
I have a page on which I'm using JQuery Mobile. I am having difficulty
Note: I'm using jQuery and jQuery Mobile. I have a mobile page which seems
I have an button in my Jquery mobile page, which is using asp.net webform.
I am creating one application with jquery.mobile-1.0a4.1 release. I have a page which is

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.