Question
Dynamically create jQuery Mobile page via JavaScript after clicking
My jQuery Mobile app consists of a single index.html
page and contains only one page with a link on startup:
<div data-role="page">
<div data-role="content">
<a id="startPageLink" href="startPage">start</a>
</div>
</div>
When the user clicks on the start link, I want to load the content for the startPage
from my JSON api asynchronously. On the callback I would like to create all the required DOM elements for startPage
via JavaScript and add the content to it. I have created a createStartPage(data)
method for this.
What is the right way to implement such dynamically created pages, so that opening index.html#startPage
also works? I think there should be a way to hook into $.mobile.changePage()
to include custom loading/page-creation code, but I did not find anything. Or is there a better solution for this problem?