Skip to content
Related Articles

Related Articles

jQuery UI Spinner option() method

View Discussion
Improve Article
Save Article
  • Last Updated : 25 Feb, 2021
View Discussion
Improve Article
Save Article

 jQuery UI consists of GUI widgets, visual effects, and themes implemented using jQuery, CSS, and HTML. jQuery UI is great for building UI interfaces for the webpages. jQuery UI spinner widget helps us to increment and decrement values of input element using up and down arrow. In this article, we will see how to use option() method in jQuery UI slider. The option() method is used to get an object for the particular current slider option in the jQuery UI spinner.

Syntax:

var a = $(".selector").spinner("option");
var a =  $(".selector").spinner("optionName","value");
 var a  =  $(".selector").spinner("options");

Approach:

  • First, add jQuery UI scripts needed for your project.

<link href = “https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css” rel=”stylesheet”>

<script src = “https://code.jquery.com/jquery-1.10.2.js”></script>

<script src = “https://code.jquery.com/ui/1.10.4/jquery-ui.js”></script>

Example 1: The following code demonstrates the .spinner(option) method.

HTML




<!doctype html>
<html lang = "en">
   <head>
      <meta charset = "utf-8">
      <link href =
         rel = "stylesheet">
      <script src =
      </script>
      <script src =
      </script>
       
      <style type = "text/css">
         #gfg input {width: 100px}
      </style>
 
      <script>
         $(function() {
            $("#gfg").spinner();
            $('button').button();
 
            var a = $("#gfg").spinner("option");
            console.log(a)
            });
 
      </script>
   </head>
    
   <body>
      <h1>GeeksforGeeks</h1>
      <h2>jQuery UI | spinner option method</h2>
      <input id = "gfg" />
   </body>
 
</html>

Output:

Console output:

Example 2:  The following code demonstrates the .spinner(optionName,value) method.

HTML




<!doctype html>
<html lang = "en">
   <head>
      <meta charset = "utf-8">
      <link href =
         rel = "stylesheet">
      <script src =
      </script>
      <script src =
      </script>
       
      <style type = "text/css">
         #gfg input {width: 100px}
      </style>
 
      <script>
         $(function() {
            $("#gfg").spinner();
            $('button').button();
 
            var a = $("#gfg").spinner("option","disabled",true);
            console.log(a)
            });
 
      </script>
   </head>
    
   <body>
      <h1>GeeksforGeeks</h1>
      <h2>jQuery UI | spinner option method</h2>
      <input id = "gfg" />
   </body>
</html>

Output:

  •       When the disabled option is false, it gives the following output.

  • When the disabled option is true, it gives the following output.                        

Example 3:  The following code demonstrates the .spinner(options) method. The following code has 2 options like { disabled: false,step: 2 }.

HTML




<!doctype html>
<html lang = "en">
   <head>
      <meta charset = "utf-8">
      <link href =
         rel = "stylesheet">
      <script src =
      </script>
      <script src =
      </script>
       
      <style type = "text/css">
         #gfg input {width: 100px}
      </style>
 
      <script>
         $(function() {
            $("#gfg").spinner();
            $('button').button();
 
            var a = $("#gfg").spinner( "option", { disabled: false,step: 2 } );
            console.log(a)
            });
      </script>
   </head>
    
   <body>
      <h1>GeeksforGeeks</h1>
      <h2>jQuery UI | spinner option method</h2>
      <input id = "gfg" />
   </body>
</html>    

Output:

Reference: https://api.jqueryui.com/category/widgets/


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!