Skip to content
Related Articles

Related Articles

jQuery Mobile Collapsible option() Method

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

jQuery Mobile is a web-based technology that can be used to make responsive content for websites that can be accessed on all types of smartphones, tablets, and desktops.  

In this article, we are going to learn the jQuery Mobile Collapsible option() method. Using this method, we can get, set or update any parameter’s value of the collapsible widget. We can also get all the options as key-value pairs using this method.

Syntax:

1. If the user wants any option’s value, the option name should be passed in the option(optionName) method. The optionName should be a string type.

  • optionName: This parameter is the input that we need to pass in the form of a string for which we need to get the value.
  • return value: We get the respective return value based on the option data type.
var isEnhanced = $("Selector").collapsible("option", "enhanced");

2. To get all the options as the key-value pairs, you just need to call the option() method with no parameter is passed to the method.

  • return: This method returns the list of key-value pairs of all the options as optionName-optionValue pairs set.
var options= $("Selector").collapsible("option");

3. To set the value of any option, you just need to call the option(optionName, value) with the optionName and the value as the parameters.

  • optionName: The option method required the option name as the first parameter and this parameter is of string type.
  • value: The option method required the option’s name as the second parameter and this parameter is of string type.
$("Selector").collapsible("option", "enhanced", "false");

4. We can also set multiple options instead of only one, you just need to call the option(options) method where options are the list of options.

  • options: It is the map of the optionName-value pairs as input to set the options corresponding to the values passed, which is of the object type.
$("Selector").collapsible("option", {enhanced: false, disabled: true});

CDN Link: Below are some jQuery Mobile scripts that will be needed for your project so add these to your project.

<link rel=”stylesheet” href=”//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.css”>
<script src=”//code.jquery.com/jquery-3.2.1.min.js”></script>
<script src=”//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.js”></script>

Example: This example describes the uses of the jQuery Mobile Collapsible option() 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=
"//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.css">
    <script src=
"//code.jquery.com/jquery-3.2.1.min.js">
</script>
    <script src=
"//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.js">
    </script>
          
    <script>
        $(function () {
            $("#btn").on('click', function () {
                var options = $("#divID").collapsible("option");
                document.getElementById('gfg').innerHTML += 
                "No of key/value pair present : " +Object.keys(options).length;
            });
        });
    </script>
</head>
      
<body>
    <center>
        <div data-role="page" id="page1">
            <div data-role="header">
                <h1 style = "color:green;">GeeksforGeeks</h1>
                <h3>
                    jQuery Mobile Collapsible option() Method
                </h3>
            </div>
      
            <div role="main" class="ui-content">
                <div data-role="collapsible" id="divID">
                    <h3>GeeksforGeeks</h3>
                    <p>
                        GeeksforGeeks is a computer science portal
                        for geeks. It contains well written, well
                        thought and well explained computer science
                        and programming articles, quizzes etc.
                    </p>
  
  
                </div>
            </div>
      
            <input type="button" id="btn"
                style="width: 200px;"
                value="Option">
            <h4><span id="gfg"></span></h4>
        </div>
    </center>
</body>
</html>


Output:

jQuery Mobile Collapsible option() Method

Reference: https://api.jquerymobile.com/collapsible/#method-option


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!