Open In App

jQuery Mobile Slider option() Method

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 using the jQuery Mobile Slider option() method. Using this method, we can get, set or update any parameter’s value of the Slider widget. We can also get all the options as key-value pairs using this method.



Syntax:

1. If we need any option’s value, pass the option name in the option(optionName) method. The optionName should be a string.



var isDisabled = $( ".selector" ).slider( "option", "disabled" );

2. Get all the options with their values as key-value pairs by just calling the option method with no parameters.

var options = $( ".selector" ).slider( "option" );

3. Set the value of any option by calling the option(optionName, value) with the optionName and the value as parameters.

$( ".selector" ).slider( "option", "disabled", true );

4) To set multiple options instead of only one, call the option(options) method where options are the list of options.

$( ".selector" ).slider( "option", { disabled: true } );

CDN Link: First, add jQuery Mobile scripts needed for your project.

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

Example: This example describes the jQuery Mobile Slider option() method.




<!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.4.5/jquery.mobile-1.4.5.min.css">
    <script src=
"//code.jquery.com/jquery-1.10.2.min.js">
    </script>
    <script src=
"//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js">
    </script>
</head>
  
<body>
    <center>
        <div data-role="page">
            <h1 style="color:green;">
                GeeksforGeeks
            </h1>
            <h3>jQuery Mobile Slider option() Method</h3>
            <div data-role="header">
                <div role="main" class="ui-content" style="width: 50%;">
                    <label for="slider">Input slider:</label>
                    <input type="range" name="slider" id="GFG" min="0" 
                           max="100" value="30">
                </div>
            </div>
            <input type="button" id="Button" value="Get the value">
            <div id="log"></div>
        </div>
    </center>
    <script>
        $(document).ready(function () {
            $("#Button").on('click', function () {
                var a = $("#GFG").slider("option", "disabled");
                $("#log").html('The value is: ' + a);
            });
        });
    </script>
</body>
  
</html>

Output:

jQuery Mobile Slider option() Method

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


Article Tags :