Following HTML markup conventions is essential to this approach because markup is the primary mechanism used to configure the mobile experience in jQuery Mobile. Validate your code and always avoid the use of inline styles or inline JavaScript event handlers to ensure the best results.
A jQuery Mobile site starts with an HTML5 'doctype'. In the 'head', references to jQuery, jQuery Mobile and the mobile theme CSS are all required to start things off:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Page Title</title>
<link rel="stylesheet" type="text/css" href="..." />
<script type="text/javascript" src="jquery-min.js"></script>
<script type="text/javascript" src="jquery-mobile-min.js"></script>
</head>
<body>
...
</body>
</html>
Inside the <body> tag, each view or "page" on the mobile device is identified with an element (usually a div) with the data-role="page" attribute:
<div data-role="page">
...
</div>
Within the "page" container, any valid HTML markup can be used, but for typical pages in jQuery Mobile, the immediate children of a "page" are divs with data-roles of "header", "content", and "footer".
<div data-role="page">
<div data-role="header">...</div>
<div data-role="content">...</div>
<div data-role="footer">...</div>
</div>
A single HTML document can contain either a single 'page' or, by stacking multiple divs with a data-role of "page", multiple 'pages' can be assembled and loaded together. This allows you to build a small site or application within a single document and jQuery Mobile will simply display the first 'page' it finds in the source order when the page loads.
Here is an example of a 2 "page" site built with two jQuery Mobile divs navigated by linking to an ID placed on each page wrapper. Note that the IDs on the page wrappers are only needed to support the internal page linking and are optional if each page is a separate HTML document.
<div data-role="page" id="foo">
I'm the "foo" page. Since I'm the first page in the source order, I will be displayed onLoad.
<a href="#bar">Visit the bar "page"</a>
</div>
<div data-role="page" id="bar">
I'm the "bar" page. I will be shown only if the anchor link on the <a href="#foo">foo</a> page is clicked.
</div>
jQuery Mobile automates the process of animating between pages, loading external pages via Ajax and tracking page history to support the Back button and deep linking. If linking between 2 "pages" inside the same HTML document, the framework will simply animate between the two page divs. If a link points to an external HTML page, jQuery Mobile will unobtrusively formulate an Ajax request based on the link's ref (Hijax), display the loading spinner, append the new page's content, apply the mobilize() function, then animate the page into view. In either situation, jQuery Mobile updates the page's URL hash to track the current page view and enable Back button support, deep-linking and bookmarking. Learn more about the technical details of the Page-Navigation-Model.
<!DOCTYPE html>
<html>
<head>
<title>My page</title>
<link rel="stylesheet" media="only all" href="css/all" />
<script type="text/javascript" src="js/all"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>My Page</h1>
<a href="index.html" class="ui-back" data-icon="arrow-l">Icon</a>
</div><!-- /header -->
<div data-role="content">
<div class="ui-body ui-body-c">
</div><!-- /ui-body wrapper -->
</div><!-- /content -->
<div data-role="footer">
...footer content goes here...
</div><!-- /footer -->
</div><!-- /page -->
</body>
</html>