Open In App

jQuery UI Sortable destroy() Method

Improve
Improve
Like Article
Like
Save
Share
Report

jQuery UI is a web-based technology and consists of various GUI widgets, visual effects, and themes. These features can be 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 destroy() method to remove the sortable functionality completely and returns the element back to its pre-init state.

Syntax:

$( ".selector" ).sortable( "destroy" );

Parameter: This method does not accept any parameter.

Return type: This method returns an object value.

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=”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 destroy() method.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" 
        href=
    <script 
    </script>
    <script 
    </script>
  
    <style>
        #sortable {
            list-style-type: none;
            width: 50%;
        }
  
        #sortable li {
            margin: 10px 0;
            padding: 0.5em;
            font-size: 25px;
            height: 20px;
            background-color: lightgreen;
        }
  
        #btn1,
        #btn2 {
            margin-left: 50px;
            padding: 0.5;
            font-size: 25px;
            height: 50px;
            width: 50%;
        }
    </style>
  
    <script>
        $(function () {
            $("#btn1").on('click', function () {
                $("#sortable").sortable("destroy");
            });
        });
    </script>
  
</head>
  
<body>
    <center>
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
  
        <h4>jQuery UI Sortable Destroy() 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>
            <li class="ui-state-default">Geeks5</li>
        </ul>
  
        <div class="res"></div>
  
        <div>
            <input type="button" 
                   id="btn1" value="Destroy">
        </div>
    </center>
  
    <script>
        $(function () {
            $("#sortable").sortable();
        });
    </script>
</body>
  
</html>


Output:

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



Last Updated : 09 Mar, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads