Skip to content
Related Articles

Related Articles

jQuery UI Sortable create Event

View Discussion
Improve Article
Save Article
Like Article
  • 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 create Event is used to trigger when an item from a connected sortable list has been dropped into another list.

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

$( ".selector" ).sortable({
    create : function( event, ui ) {}
});
  • Bind an event listener to the sort create an event:

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

Parameters: These are the following parameters that are accepted.  

  • event: This event is triggered when the sort creates 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 }.

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 create 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({
                   create : function (event, ui) {
                    $(".res").html ($(".res").html () 
                     + "<b>Sortable Widget  has been created.</b><br>");
                   }
            });
            $( "#sortable-2" ).sortable({
                   connectWith : "#sortable-1, #sortable-2"
            });
        });
    </script>
    
</head>
    
<body>
    <center>
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
    
        <h4>jQuery UI Sortable create 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 create Event

jQuery UI Sortable create Event

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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!