2

I created a page with jQuery Mobile, and tried to add content dynamically:

    $(function () {

        $("#deviceTarget").sortable({
            revert: true
        });

        $("body > div[data-role='page']").append($("<div data-role='header' data-theme='a' data-position='fixed'><h1>Header</h1></div>"));
        $("body > div[data-role='page']").append($("<div data-role='footer' data-theme='a' data-position='fixed'><h1>Footer</h1></div>"));
        $.mobile.activePage.trigger("create");

    });

    $(document).bind('mobileinit',function(){
        $.mobile.defaultPageTransition = 'none';
        $.mobile.selectmenu.prototype.options.nativeMenu = false;
      });

    function refreshPage() {
        $.mobile.activePage.trigger("create");
    }

But I got the result (image).

I want to get the result (image).

How can I do?

Thanks.

1 Answer 1

4

all you need to do is to refresh the page

not sure about this code:

    $.mobile.activePage.trigger("refresh");

but it should work. Otherwise take a look at this jquerymobile.com article.

9
  • I tried $.mobile.activePage.trigger("refresh"), but not worked.
    – Jeff Chu
    Mar 6, 2012 at 10:40
  • maybe i got your question in the wrong way. Can you explain further? what do you mean by result different to use static layout?
    – Th0rndike
    Mar 6, 2012 at 10:46
  • I added screenshot to indicate my situation.
    – Jeff Chu
    Mar 6, 2012 at 14:32
  • This is obviously a jquery refresh problem. Maybe changing "create" to "refresh" could work. Or even calling first "create" and then "refresh". By the site I linked on the answer, you should use create if you create new objects, and refresh if you add new items to an existing content, so create in your case should be right. Another thing that comes to my mind is that the jquery css is not properly linked, can you check that out?
    – Th0rndike
    Mar 6, 2012 at 14:43
  • 1
    But, I tried "create" and "refresh", both not worked... I just link jQuery mobile's CSS from jQuery CDN source.
    – Jeff Chu
    Mar 6, 2012 at 15:21

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.