Open In App
Related Articles

jQuery Mobile panel beforeclose Event

Improve Article
Save Article
Like Article

jQuery Mobile is a set of HTML5 based user interface systems that is built on top of jQuery. It is used for creating responsive and accessible websites and web apps for a variety of devices like mobiles, tablets, laptops, and desktops.

In this article, we will be using the jQuery Mobile panel beforeclose event that triggers when the process of closing the panel starts.


  • Initialize the panel with beforeclose callback specified:

    $( ".selector" ).panel({
      beforeclose: function( event, ui ) {
          // Your code here
  • Bind an event listener to the panelbeforeclose event:

    $(".selector").on( "panelbeforeclose", function( event, ui ) {} );

Parameters: It accepts a callback function that has two parameters:

  • event: It accepts Event type value.
  • ui: It accepts Object type value. The ui object can be empty but used for consistency with other events across the library.

CDN links:

<link rel=”stylesheet” href=”” />
<script src=””></script>
<script src=””></script>

Example: In the example below, an alert box appears when the beforeclose event is fired.


<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <meta name="viewport" content=
          "width=device-width, initial-scale=1">
    <link rel="stylesheet" href=
    <script src=
    <script src=
        $(document).ready(function () {
             // Initialize the panel with
              // beforeclose callback specified
                beforeclose: function (event, ui) {
                    alert("Panel beforeclose event fired.")
          // A function to close the panel.
        function closePanel() {
    <div data-role="page">
        <div data-role="header">
            <h1 style="color:green;">GeeksforGeeks</h1>
            <h3>jQuery Mobile Panel beforeclose event</h3>
        <div role="main" class="ui-content">
                <a href="#divID">Open Panel</a>
        <div data-role="panel" id="divID">
            <button onclick="closePanel();">Close Panel</button>




Last Updated : 07 Jan, 2022
Like Article
Save Article
Similar Reads
Related Tutorials