Injecting content into the DOM, changePage to content, update history in V 1.0a3
I wasted a lot of time on this today because of a lack of documentation or simply my inability to find that documentation so I hope this helps some others out.
I needed to be able to dynamically append content to the DOM, then switch to that content while updating history so that the back button works as expected.
The thing that tripped be up was
the assignment of a div data-url attribute as opposed to previously just assigning an id to the div.
This is a snippet of the code that injects the html into the DOM ..
- var p = [];
- p.push('<div data-role="page" data-theme="b" data-url="details">');
- p.push('<div data-role="header" data-theme="b">');
- p.push('<h1>Project Details</h1>');
- p.push('</div>');
- p.push('<div data-role="content">');
- p.push('<div id="a5_details"></div>');
- p.push('</div>');
- p.push('</div>');
- $('body').append(p.join(''));
And here is the method to switch to that page ..
- $.mobile.changePage("#details","slide",false,true);
Hope that helps.