Horje
jQuery UI Sortable widget() Method

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 will be using the jQuery UI Sortable widget() method to return a jQuery object containing the sortable element. It does not accept any parameter for functioning.

Syntax:

var widget = $( ".selector" ).sortable( "widget" );

Parameter: This method does not accept any parameter.

Return type: This method returns an object value that contains the sortable element.

CDN Link: The following jQuery Mobile scripts will be needed for your project so we need to add these scripts to your project.

<link rel=”stylesheet” href=”https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css”>
<script src= “https://code.jquery.com/jquery-1.12.4.js”></script>
<script src= “https://code.jquery.com/ui/1.12.1/jquery-ui.js”></script>

Example: This example describes the uses of the jQuery UI Sortable widget() Method.

HTML

<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="utf-8">
    <link rel="stylesheet"
        href=
    <script
        src=
    </script>
    <script
        src=
    </script>
  
    <style>
        #sortable {
            list-style-type: none;
            width: 50%;
        }
  
        #sortable li {
            margin: 10px 0;
            padding: 0.5em;
            font-size: 25px;
            height: 20px;
            background-color: #7af760;
        }
        #btn1, #btn2
        {
            margin-left: 50px;
            padding: 0.5;
            font-size: 25px;
            height: 50px;
            width: 50%;
        }
    </style>
    <script>
        $(function () {
            $("#btn").on('click', function () {
                var widget = $("#divID").sortable( "widget" );
                document.getElementById('gfg').innerHTML += 
                "No of jQuery object containing the sortable element : " 
                  + Object.keys(widget).length;
            });
        });
  
        $(function () {
            $("#sortable").sortable();
        });
    </script>
  
</head>
  
<body>
    <center>
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
  
        <h4>jQuery UI Sortable widget() 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>
        </ul>
          
        <input type="button" id="btn"
            value="Widget">
          
        <h4><span id="gfg"></span></h4>
          
    </center>
</body>
  
</html>

Output:

jQuery UI Sortable widget() Method

jQuery UI Sortable widget() Method

Reference: https://api.jqueryui.com/sortable/#method-widget




Reffered: https://www.geeksforgeeks.org


JQuery

Related
jQuery Mobile Selectmenu iconpos Option jQuery Mobile Selectmenu iconpos Option
jQuery Mobile Selectmenu iconshadow Option jQuery Mobile Selectmenu iconshadow Option
jQuery Mobile Slider classes Option jQuery Mobile Slider classes Option
jQuery Mobile Filterable filterTheme Option jQuery Mobile Filterable filterTheme Option
jQuery UI Droppable option() Method jQuery UI Droppable option() Method

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
8