jQuery Mobile: First simple button example

We will start off with the first example by creating a button using jQuery Mobile.

<div data-role='page'>
    <div data-role='header'><h1>My Mobile App</h1></div>
    <div data-role='content'>
        <p>Look at the button!</p>
        <a href='#' data-role='button'>I am a button</a>
    </div>
</div>
Try The Code

To create a button, we use the attribute data-role=”button” as in the following line:

<a href='#' data-role='button'>I am a button</a>

The href link will tell the app where to go when the button is clicked.

Since we have href=’#’, which is itself, the page will not go anywhere when it is clicked.

jqm2

Code Block
<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css' rel='stylesheet' type='text/css'/>
    <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>
    <meta charset='utf-8'>
    <title>JS Bin</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>My Mobile App</h1></div>
    <div data-role='content'>
        <p>Look at the button!</p>
        <a href='#' data-role='button'>I am a button</a>
    </div>
</div>
</body>
</html>
Series Navigation<< jQuery Mobile: Adding jQuery Mobile to the App
jQuery Mobile: Data-role >>