jQuery UI Sortable dropOnEmpty Option
Last Updated :
25 Jan, 2022
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 learn how to use the jQuery UI Sortable dropOnEmpty Option. Using this option, items from this sortable can't be dropped on an empty connect sortable, if is set to false.
Syntax:
The dropOnEmpty option takes a boolean value and the syntax is as follows. If false, we can't be dropped any item on an empty connect sortable and vice-versa.
$( ".selector" ).sortable({
dropOnEmpty: false
});
Get the dropOnEmpty option
var dropOnEmpty = $( ".selector" )
.sortable( "option", "dropOnEmpty" );
Set the dropOnEmpty option
$( ".selector" ).sortable( "option", "dropOnEmpty", false );
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 dropOnEmpty Option.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<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>
<style>
.list {
background-color: green;
border: 1px solid gray;
}
.items {
list-style-type: none;
margin-left: 5px;
padding: 0;
width: 200px;
float: left;
}
.items li {
margin: 5px;
padding: 5px;
cursor: pointer;
border-radius: 5px;
font-size: 20px;
}
.o {
background-color: #00ff44;
}
</style>
<script>
$(function () {
$("#sortable1,#sortable3").sortable({
connectWith: "#sortable3",
dropOnEmpty: true
});
$("#sortable2").sortable({
connectWith: "#sortable3",
dropOnEmpty: false
});
$("#sortable1, #sortable2,
#sortable3").disableSelection();
});
</script>
</head>
<body>
<center>
<h1 style="color:green;">
GeeksforGeeks
</h1>
<h4>jQuery UI Sortable dropOnEmpty Option</h4>
<ul id="sortable1" class="items">
<li class="list">Drop on empty</li>
<li class="list">Drop on empty</li>
</ul>
<ul id="sortable2" class="items">
<li class="list o">No drop on empty</li>
<li class="list o">No drop on empty</li>
</ul>
<ul id="sortable3" class="items"
style="height:200px;background-color:#a0ff94">
</ul>
</center>
</body>
</html>
Output:
jQuery UI Sortable dropOnEmpty Option
Reference: https://api.jqueryui.com/sortable/#option-dropOnEmpty
Similar Reads
jQuery UI Sortable delay Option jQuery UI sortable widget delay option is used to set the time in milliseconds to define when the sorting should start. Syntax: $( ".selector" ).sortable({ delay: 150 }); Approach: First, add jQuery UI scripts needed for your project. <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/theme
1 min read
jQuery UI Sortable appendTo Option The Sortable widget appendTo option is used to append the elements when the sortable elements are dragged with mouse. Syntax: $( ".selector" ).sortable({ appendTo: document.body }); Approach: First, add jQuery UI scripts needed for your project. <link rel="stylesheet" href="//code.jquery.com/ui/1
1 min read
jQuery UI Sortable distance Option 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 app
2 min read
jQuery UI Sortable cursorAt Option jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Sortable cursorAt option is used to move the cursor at a given position at the time of sorting. This option is working
1 min read
jQuery UI Sortable containment Option 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
2 min read