0%
Loading ...

JQuery Mobile – Lesson 02 – Switching between pages

JQuery Mobile – Lesson 02 – Switching between pages

Lesson 01 | Lesson 02 | Lesson 03 | Lesson 04 | Lesson 05


1. In continuation to Lesson 01, We will learn how to switch between div pages.

2. Let’s give each page an different ID:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Page title</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" /> <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
    <div data-role="page" id="page1">
       <div data-role="header">
       <h1>Page 1 header</h1>
       </div>

       <div data-role="main" class="ui-content">
       <h1>Page 1 Main</h1>
       </div>

       <div data-role="footer">
       <h1>Page 1 footer</h1>
       </div>
    </div>

    <div data-role="page" id="page2">
       <div data-role="header">
       <h1>Page 2 header</h1>
       </div>

       <div data-role="main" class="ui-content">
       <h1>Page 2 Main</h1>
       </div>

       <div data-role="footer">
       <h1>Page 2 footer</h1>
       </div>
    </div>
</body>
</html>

3. After adding the tags (marked red) below, you should browse from one page to the other:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Page title</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" /> <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
    <div data-role="page" id="page1">
       <div data-role="header">
       <h1>Page 1 header</h1>
       </div>

       <div data-role="main" class="ui-content">
       <h1>Page 1 Main</h1>
       <a href="#page2">page 2</a>      
       </div>

       <div data-role="footer">
       <h1>Page 1 footer</h1>
       </div>
    </div>

    <div data-role="page" id="page2">
       <div data-role="header">
       <h1>Page 2 header</h1>
       </div>

       <div data-role="main" class="ui-content">
       <h1>Page 2 Main</h1>
       <a href="#page1">page 1</a>
       </div>

       <div data-role="footer">
       <h1>Page 2 footer</h1>
       </div>
    </div>
</body>
</html>