The jQuery Mobile framework provides the page plugin which automatically handles page initialization events. The pagebeforecreate
event is fired before the page is created. The pagecreate
event is fired after the page is created but before the widgets are initialized. The pageinit
event is fired after the complete initialization. This recipe shows you how to use these events.
Copy the full code of this recipe from the code/08/pageinit
sources folder. You can launch this code using the URL http://localhost:8080/08/pageinit/main.html
Carry out the following steps:
Create
main.html
with three empty<div>
tags as follows:<div id="content" data-role="content"> <div id="div1"></div> <div id="div2"></div> <div id="div3"></div> </div>
Add the following script to the
<head>
section to handle thepagebeforecreate
event:var str = "<a href='#' data-role='button'>Link</a>...