Open In App

jQuery UI Sortable remove Event

Last Updated : 20 Jan, 2022
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.

The jQuery UI Sortable remove Event is used to trigger when an item from a connected sortable list has been dropped into another list and the former is the event target source.

Syntax: We need to initialize the sortable widget with the remove callback function

$( ".selector" ).sortable({

remove : function( event, ui ) {}

});
  • Bind an event listener to the sort remove event:

    $( ".selector" ).on( "sortremove", function( event, ui ) {} );

Parameters: These are the following parameters that are accepted.

  • event: This event is triggered when an item is removed from the sort list.
  • ui: This parameter is of type object with below-given options.
    • helper: This parameter is the jQuery object representing the sorted helper.
    • item: This parameter is the jQuery object that represents the current dragged item.
    • offset: This parameter is the current absolute position of the helper object which is represented as { top, left }.
    • position: This parameter is the current position of the helper object which is represented as { top, left }.
    • originalPosition: This parameter is the original position of the helper object which is represented as { top, left }.
    • placeholder: This parameter is the element that is used as a placeholder. This is of type jQuery object.

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 remove Event.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="utf-8">
    <link rel="stylesheet"
          href=
    <script 
          src=
    </script>
    <script 
          src=
    </script>
  
    <style>
        #sortable-1, #sortable-2 { 
            list-style-type: none; 
            width: 150px; 
            }
        #sortable-1 li, #sortable-2 li { 
            padding: 0.4em; 
            font-size: 17px; 
            height: 16px; 
            color: black;
            background-color: green;
        }
  
    </style>
  
    <script>
        $(function() {
            $( "#sortable-2" ).sortable();
            $( "#sortable-1" ).sortable({
                   remove : function (event, ui) {
                    $(".res").html ($(".res").html () 
                     + "<b>Removed</b><br>");
                   }
            });
            $( "#sortable-1" ).sortable({
                   connectWith : "#sortable-1, #sortable-2"
            });
        });
    </script>
  
</head>
  
<body>
    <center>
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
  
        <h4>jQuery UI Sortable remove Event</h4>
  
        <hr />
        <div class = "list_data">
            <div class = "list_data1"
                <h3>Name</h3>
                <ul id = "sortable-1">
                    <li class = "ui-state-default">GFG1</li>
                    <li class = "ui-state-default">GFG2</li>
                    <li class = "ui-state-default">GFG3</li>
                </ul>
            </div>
            <div class = "list_data1">
                <h3>Mark</h3
                <ul id = "sortable-2">
                    <li class = "ui-state-default">90</li>
                    <li class = "ui-state-default">80</li>
                    <li class = "ui-state-default">70</li>
                </ul>
            </div>
        </div>
          
        <hr />
        <div class="res"></div>
    </center>
</body>
  
</html>


Output:

jQuery UI Sortable remove Event

Reference: https://api.jqueryui.com/sortable/#event-remove 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads