Open In App
Related Articles

jQuery UI Sortable option() Method

Improve Article
Save Article
Like Article

jQuery UI  is a web-based technology and consists of GUI widgets, visual effects, and themes implemented using the jQuery, JavaScript Library. jQuery UI is the best tool for building UI interfaces for the webpages. It can also be used to build highly interactive web applications or can be used to add widgets easily.

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


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").sortable("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 value: This method returns the list of key-value pairs of all the options as optionName-optionValue pairs set.

var options= $("Selector").sortable("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").sortable("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").sortable("option", {enhanced: false, disabled: true});

CDN Link: Add the below jQuery Mobile scripts that will be needed for your project.

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

Example: This example demonstrates the jQuery UI Sortable option() method.


<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <link rel="stylesheet" href=
    <script    src=
    <script    src=
        #sortable {
            list-style-type: none;
            width: 50%;
        #sortable li {
            margin: 10px 0;
            padding: 0.5em;
            font-size: 25px;
            height: 20px;
            background-color: #7af760;
            margin-left: 50px;
            padding: 0.5;
            font-size: 25px;
            height: 50px;
            width: 50%;
        $(function () {
            $("#btn").on('click', function () {
                var options = $("#divID").sortable("option");
                document.getElementById('spanID').innerHTML += 
                "No of key/value pair present : " 
                + Object.keys(options).length;
        $(function () {
        <h1 style="color:green;">
        <h4>jQuery UI Sortable option() Method</h4>
        <ul id="sortable">
            <li class="ui-state-default">Geeks1</li>
            <li class="ui-state-default">Geeks2</li>
            <li class="ui-state-default">Geeks3</li>
            <li class="ui-state-default">Geeks4</li>
        <input type="button" id="btn" value="Option">
        <h4><span id="spanID"></span></h4>        


jQuery UI Sortable option() Method

jQuery Mobile Sortable option() Method


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