jQuery Mobile: A basic popup

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

Popups are useful in many ways.

jQM supports various types of popup.  From a small tooltip to a large photo lightbox.

To create a popup, add the data-role=’popup’ attribute to a <div> with the contents.  Then create a link with the href set to the id of the popup <div>, and add the attribute data-rel=’popup’ to tell the framework to open the popup when the link is tapped.

A popup <div> has to be nested inside the same page as the link.

<!DOCTYPE html>
    <link href='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.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.1/jquery.mobile-1.4.1.min.js'></script>
<div data-role='page'>
    <div data-role='header' data-theme='b'>
        <h1>Welcome To My Popup App</h1>

    <div data-role='content' style='text-align: center'>
        <a href='#popupBasic' data-rel='popup' class='ui-btn ui-corner-all ui-shadow ui-btn-inline' data-transition='pop' >Basic Popup</a>
        <div data-role='popup' id='popupBasic'>
            <p>This is a completely basic popup, no options set.</p>

    <div data-role='footer' data-position='fixed'>
        <h4 style='text-align:center;'>I'm the footer</h4>

Try The Code
Series Navigation<< jQuery Mobile: Navigation bar and header in swatch b
jQuery Mobile: Tooltip >>

Leave a comment

Leave a Reply