Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

jQuery UI Sortable beforeStop Event

  • Last Updated : 20 Jan, 2022

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 beforeStop Event is used to trigger when sorting stops, but when the placeholder/helper is still available.

Syntax:

We need to initialize the sortable widget with the beforeStop callback function

$( ".selector" ).sortable({

beforeStop : function( event, ui ) {}

});
  • Bind an event listener to the sortbeforestop event:

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

Parameters: These are the following parameters that are accepted.  

  • event: This event is triggered when the sort beforestop an item.
  • 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 }.
    • sender: This parameter is the sortable item of type jQuery object coming from moving from one sortable to another.
    • 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 beforeStop 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-1" ).sortable({
                beforeStop : function (event, ui) {
                    $(".res").html ($(".res").html ()
                    + "<b>beforeStop</b><br>");
                }
            });
            $( "#sortable-2" ).sortable({
                connectWith : "#sortable-1, #sortable-2"
            });
        });
    </script>
  
</head>
  
<body>
    <center>
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
  
        <h4>jQuery UI Sortable beforeStop 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 beforeStop Event

jQuery UI Sortable beforeStop Event

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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!