jQuery Moble: Page movement

This entry is part 8 of 73 in the series jQuery Mobile

In this post, we first learn how to define a second page.  This is done by:

<div data-role='page' id='pagetwo'>
    <div data-role='header'><h1>My Mobile App</h1></div>
    <div data-role='content'>
        <p>You are at page two!</p>
        <a href='#pageone' data-role='button'>Go Back</a>
    </div>
</div>

We create another div with data-role=’page’.  We also need to put an id to this page.

Since this app will only keep cycling between pageone and pagetwo, we have a href pointing back to pageone in line 21 below.

There are 2 data-roles with page attributes in lines 10 and17.

The whole code structure is as below:
<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css' rel='stylesheet'/>
    <script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
    <script src='http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js'></script>
    <title>Codecrawl</title>
</head>
<body>
<div data-role='page' id='pageone'>
    <div data-role='header'><h1>My Mobile App</h1></div>
    <div data-role='content'>
        <p>Your page one content here</p>
        <a href='#pagetwo' data-role='button'>Click Me</a>
    </div>
</div>
<div data-role='page' id='pagetwo'>
    <div data-role='header'><h1>My Mobile App</h1></div>
    <div data-role='content'>
        <p>You are at page two!</p>
        <a href='#pageone' data-role='button'>Go Back</a>
    </div>
</div>
</body>
</html>
Try The Code

You can try running the script here.

Series Navigation<< jQuery Mobile: Link to a page
jQuery Mobile: Fixed footer >>

Leave a comment

Leave a Reply