Skip to content
Related Articles

Related Articles

jQuery Mobile panel toggle() Method

View Discussion
Improve Article
Save Article
  • Last Updated : 10 Jan, 2022
View Discussion
Improve Article
Save Article

jQuery Mobile is a JavaScript library that is used to develop responsive websites and web applications. It is built on top of jQuery. In this article, we will use the jQuery Mobile panel toggle() method to toggle the state of the panel, that is, if the panel is closed, it will open and if it is open it will be closed.

Syntax:

$(".selector").panel( "toggle" );

Arguments: This method does not accept any arguments.

CDN Links: We must include jQuery mobile in our code to use it.

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

Example: The below example demonstrates the use of the panel toggle() method.  

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="utf-8">
    <meta name="viewport" content=
          "width=device-width, initial-scale=1">
  
    <link rel="stylesheet" href=
    <script src=
    </script>
    <script src=
    </script>
  
    <script>
        function togglePanel(){
            // Invoke the panel toggle() method
            $("#divID").panel("toggle");
        }
    </script>
</head>
  
<body>
  
    <div data-role="page">
        <div data-role="header" >
            <h1 style="color:green;">GeeksforGeeks</h1>
            <h3>jQuery Mobile Panel toggle() method</h3>
        </div>
  
        <div role="main" class="ui-content">
            <center>
                <button onclick="togglePanel();" style="width:400px;"
                   Toggle Panel
               </button>
            </center>
          </div>>
  
        <div data-role="panel" id="divID">
            <h3>GeeksforGeeks</h3>
            <button onclick="togglePanel();">Toggle Panel</button>
        </div>
    </div>
</body>
</html>


Output:

Reference: https://api.jquerymobile.com/panel/#method-toggle 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!