1

I would like to append some code to a page using jQuery/jQuery mobile, but I am tripping up on some of the page() and pageshow and refresh methods.
Here is my code. you can cut, paste and run as is.

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Page Title</title>   
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"></script>

    <script>
    //$(document).ready(function()                  // get error when I use this
    $('div').live('pageshow', function () {  
        function fnCreateGroups(){
            var section = "<p>and add a whole bunch of html code...</p>";
             myClone = $(section);  
             alert((myClone).html());  // this works
             myClone.appendTo("#placeholder").page(); // but not appending          
        }
        fnCreateGroups();
    });         
    </script>

</head> 
<body> 
    <div data-role="page">
        <div id="placeholder">
            <div data-role="content">
                <div id="placeholder">this is a small amount of html code.</div>
            </div>
        </div>      
    </div>
</body>
</html>

1 Answer 1

0

Beta2 release notes:

instead of:

myClone.appendTo("#placeholder").page();

try

myClone.appendTo("#placeholder").trigger('create');

From your comment:

You are running the live() on all div's

$('div').live('pageshow', function () 

try using the page id instead

$('#change_this_page_only').live('pageshow', function () 

and this:

<div data-role="page">

to something like this:

<div data-role="page" id="change_this_page_only">
Sign up to request clarification or add additional context in comments.

2 Comments

thank you that works! My other issue is that I have several pages and I only want to run it once. However every time I enter the page it repeats.
Thank you. With your help, I have advanced more in 7 minutes than in last 12 hours!!!!! I posted new question that builds on this examples.stackoverflow.com/questions/7029533/… Thanks again!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.