jQuery Mobile: An Example UI

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

With jQuery Mobile, you can quickly build the user interface of an App.

We look at this simple UI built using jQuery Mobile.

Sample UI
<!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>Upwhere</title>
</head>
<body>
  <div data-role="page">
  <div data-role="header">
    <h1>Welcome To My Mobile App</h1>
    <div data-role="navbar">
      <ul>
        <li><a href="#" data-icon="home">Home</a></li>
        <li><a href="#" data-icon="arrow-r">Latest Posts</a></li>
        <li><a href="#" data-icon="search">Search</a></li>
      </ul>
    </div>
  </div>

  <div data-role="content">
    <p>You can put your content here...</p>
  </div>

  <div data-role="footer">
    <h1>My Footer</h1>
  </div>
</div> 

</body>
</html>
Try The Code

For this series of tutorials, we will put our code into jsbin instead of jsfiddle.

The output, as shown in the jsbin is:

jq1

Page Sections

There are 4 sections in the page:

  1. The header,
  2. the navigation bar,
  3. the content and
  4. the footer.

The main code of the 4 sections is wrapped inside the body tag as shown below.

jQM Body
<body>
<div data-role="page">
  <div data-role="header">
    <h1>Welcome To My Mobile App</h1>
    <div data-role="navbar">
      <ul>
        <li><a href="#" data-icon="home">Home</a></li>
        <li><a href="#" data-icon="arrow-r">Latest Posts</a></li>
        <li><a href="#" data-icon="search">Search</a></li>
      </ul>
    </div>
  </div>
 
  <div data-role="content">
    <p>You can put your content here...</p>
  </div>
 
  <div data-role="footer">
    <h1>My Footer</h1>
  </div>
</div> 
</body>

Each section of the page is defined by a data-role attribute.

Looking at the code above, you could see that it is relatively easy to design the UI using jQM.

Series Navigation<< jQuery Mobile: Introduction
jQuery Mobile: Adding jQuery Mobile to the App >>