Open In App

How to create a Closing Popup using jQuery Mobile ?

Improve
Improve
Like Article
Like
Save
Share
Report

jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets, and desktops. In this article, we will be creating a closing popup using jQuery Mobile.

Approach: Add jQuery Mobile scripts needed for your project.

<link rel=”stylesheet” href=”http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css” />
<script src=”http://code.jquery.com/jquery-1.11.1.min.js”></script>
<script src=”http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js”></script>

We will create a popup containing a closing button. The closing button can be placed either left-top or right-top or other places based on classes. The popup can be closed by clicking outside of the popup widget or pressing Esc key. The data-dismissible=”false” attribute is used to prevent the closing popup when user click outside the popup box. 

Example 1: We will create a popup containing a close button at top-right corner.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <link rel="stylesheet" href=
  
    <script src=
    </script>
  
    <script src=
    </script>
</head>
  
<body>
    <center>
        <h1>GeeksforGeeks</h1>
  
        <h4>
            Design a Popup with right close 
            button using jQuery Mobile
        </h4>
  
        <a href="#CloseRightPopup" data-rel="popup" 
            class="ui-btn ui-corner-all ui-shadow ui-btn-inline">
            Popup with Right close button
        </a>
  
        <div data-role="popup" id="CloseRightPopup" 
            class="ui-content" style="max-width:280px">
            <a href="#" data-rel="back"
                class="ui-btn ui-corner-all ui-shadow 
                ui-btn-a ui-icon-delete ui-btn-icon-notext 
                ui-btn-right">
                Close
            </a>
  
            <p>
                It is an example of popup with 
                closing of top-right corner.
            </p>
        </div>
    </center>
</body>
  
</html>


Output:

Example 2: We will create a popup containing a close button at top-left corner.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <link rel="stylesheet" href=   
  
    <script src=
    </script>
  
    <script src=
    </script>
</head>
  
<body>
    <center>
        <h1>GeeksforGeeks</h1>
  
        <h4>
            Design a Popup with left close
            button using jQuery Mobile
        </h4>
  
        <a href="#CloseLeftPopup" 
            data-rel="popup" 
            class="ui-btn ui-corner-all ui-shadow 
            ui-btn-inline">
            Popup with Left close button
        </a>
              
        <div data-role="popup" id="CloseLeftPopup" 
            class="ui-content" style="max-width:280px">
            <a href="#" data-rel="back"
                class="ui-btn ui-corner-all ui-shadow 
                ui-btn-a ui-icon-delete ui-btn-icon-notext 
                ui-btn-left">
                Close
            </a>
  
            <p>
                It is an example of popup with 
                closing of top-left corner.
            </p>
        </div>
    </center>
</body>
  
</html>


Output:



Last Updated : 14 Dec, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads