Getting Started with jQuery Mobile

Tutorial 1 of 5

Getting Started with jQuery Mobile

1. Introduction

1.1 Tutorial's Goal

This tutorial aims to introduce you to jQuery Mobile, a user-interface system designed to make responsive web sites and apps that are accessible on all smartphones, tablets, and desktop devices.

1.2 Learning Outcome

By the end of this tutorial, you will have a basic understanding of jQuery Mobile, its features, and benefits. You will be able to set up a simple jQuery Mobile project.

1.3 Prerequisites

  • Basic knowledge of HTML, CSS, and JavaScript.
  • A text editor (like Sublime Text or Notepad++) and a modern web browser for testing.

2. Step-by-Step Guide

2.1 What is jQuery Mobile?

jQuery Mobile is a HTML5-based user interface system designed to make responsive websites and apps that are accessible in all smartphone, tablet and desktop devices. It is built on the rock-solid jQuery and jQuery UI foundation, and offers a range of user interface widgets.

2.2 Installation

To start using jQuery Mobile, include the following code in your HTML file's head section:

<head>
    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!-- jQuery Mobile library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>
</head>

2.3 Basic Page Structure

A basic page in jQuery Mobile consists of a page wrapper with a header, content, and footer div.

<div data-role="page">
    <div data-role="header">...</div>
    <div data-role="content">...</div>
    <div data-role="footer">...</div>
</div>

3. Code Examples

3.1 Example 1: Simple jQuery Mobile Page

<!DOCTYPE html>
<html>
<head>
    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!-- jQuery Mobile library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>
</head>
<body>
    <div data-role="page">
        <div data-role="header">
            <h1>My Page</h1>
        </div>
        <div data-role="content">
            <p>Hello World!</p>
        </div>
        <div data-role="footer">
            <h4>My Footer</h4>
        </div>
    </div>
</body>
</html>

This will create a simple page with a header, content, and footer section.

3.2 Example 2: jQuery Mobile Buttons

You can create buttons in jQuery Mobile by using the data-role="button" attribute.

<a href="#" data-role="button">Button</a>

This will create a button with the text "Button".

4. Summary

In this tutorial, we introduced jQuery Mobile, a powerful tool for creating mobile-optimized web applications. We covered its installation, basic page structure, and how to create simple elements like buttons.

For further learning, explore more complex jQuery Mobile widgets like toolbars, navbars, and listviews. Official documentation and additional resources can be found here.

5. Practice Exercises

5.1 Exercise 1

Create a jQuery Mobile page with a header, content, and footer. The content should include a button.

5.2 Exercise 2

Create a jQuery Mobile page with a navbar in the header. The navbar should include three buttons.

Practice makes perfect. The more you practice, the more comfortable you will become with jQuery Mobile. Happy coding!