I am building a workout catalog using jquery mobile for the UI and jquery templates to deal with the html. I have been able to append html to an already created page AND get jquery mobile to change the markup thanks to the .page() function.
However, I want to be able to create new jq mobile pages. I can inject code into divs with data-role=page, call .page() on it and it's all fine. But appending a fully made page to the body does not work.
EDIT: This question and my answer refers to jquery mobile alpha 3
Ok I got it. If you want to add a to the DOM you have to also add a value for data-url. When you create a static html page,
<div data-role="page" id="home">
jQuery mobile automatically adds a data-url equal to the id you give it. When you do it yourself, you have to hold its hand and pass it a data-url="home".
When you generate your html string append it to $.mobile.pageContainer so jQuery Mobile knows where to find it (appending it to the body works also, but it's probably best not to rock the boat).
After that, call .page() on your page in the DOM so that jQuery mobile does all of its magical <span>
magic to make it pretty.
$('#home').page();
Gravedigging this thread. Using the jquery mobile (1.1.0), this was working for me, .trigger("create")
...
content = '<div data-role="page" id="myID" data-url="myID">'
// ...
$('body').append(content).trigger("create")
$("<a href='#myID' data-rel='dialog'/>").trigger("click")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With