jQuery UI Droppable creates a target that can receive elements made draggable with Draggable.
$( "#draggable" ).draggable();
$( "#droppable" ).droppable({
drop: function ( event, ui ) {
$( this ).find( "p" ).text( "Dropped!" );
}
});
Controls which draggable elements the target accepts.
$( "#droppable" ).droppable({
accept: ".accepted"
});
Read the current option:
const value =
$( "#droppable" ).droppable( "option", "accept" );
Set the option after initialization:
$( "#droppable" ).droppable(
"option",
"accept",
".accepted"
);
Legacy option that adds a class while an acceptable draggable is active.
classes option with ui-droppable-active instead.$( "#droppable" ).droppable({
activeClass: "ui-state-highlight"
});
Read the current option:
const value =
$( "#droppable" ).droppable( "option", "activeClass" );
Set the option after initialization:
$( "#droppable" ).droppable(
"option",
"activeClass",
"ui-state-highlight"
);
Controls whether the base ui-droppable class is added.
$( "#droppable" ).droppable({
addClasses: false
});
Read the current option:
const value =
$( "#droppable" ).droppable( "option", "addClasses" );
Set the option after initialization:
$( "#droppable" ).droppable(
"option",
"addClasses",
false
);
Adds custom classes to Droppable structural states such as ui-droppable, ui-droppable-active and ui-droppable-hover.
$( "#droppable" ).droppable({
classes: { "ui-droppable": "highlight" }
});
Read the current option:
const value =
$( "#droppable" ).droppable( "option", "classes" );
Set the option after initialization:
$( "#droppable" ).droppable(
"option",
"classes",
{ "ui-droppable": "highlight" }
);
Disables dropping when set to true.
$( "#droppable" ).droppable({
disabled: true
});
Read the current option:
const value =
$( "#droppable" ).droppable( "option", "disabled" );
Set the option after initialization:
$( "#droppable" ).droppable(
"option",
"disabled",
true
);
For nested droppables, prevents a parent target from acting as though it received the draggable when the child handles it.
$( "#droppable" ).droppable({
greedy: true
});
Read the current option:
const value =
$( "#droppable" ).droppable( "option", "greedy" );
Set the option after initialization:
$( "#droppable" ).droppable(
"option",
"greedy",
true
);
Legacy option that adds a class while an accepted draggable is over the target.
classes.ui-droppable-hover instead.$( "#droppable" ).droppable({
hoverClass: "drop-hover"
});
Read the current option:
const value =
$( "#droppable" ).droppable( "option", "hoverClass" );
Set the option after initialization:
$( "#droppable" ).droppable(
"option",
"hoverClass",
"drop-hover"
);
Groups compatible draggable and droppable elements.
$( "#droppable" ).droppable({
scope: "files"
});
Read the current option:
const value =
$( "#droppable" ).droppable( "option", "scope" );
Set the option after initialization:
$( "#droppable" ).droppable(
"option",
"scope",
"files"
);
Controls how overlap is tested: fit, intersect, pointer or touch.
$( "#droppable" ).droppable({
tolerance: "pointer"
});
Read the current option:
const value =
$( "#droppable" ).droppable( "option", "tolerance" );
Set the option after initialization:
$( "#droppable" ).droppable(
"option",
"tolerance",
"pointer"
);
Remove Droppable behavior completely.
$( "#droppable" ).droppable( "destroy" );
Temporarily disable the drop target.
$( "#droppable" ).droppable( "disable" );
Re-enable a disabled drop target.
$( "#droppable" ).droppable( "enable" );
Return the Droppable widget instance.
$( "#droppable" ).droppable( "instance" );
Read or change options. The example reads all current options.
const options = $( "#droppable" ).droppable( "option" );
Return the jQuery object representing the droppable element.
$( "#droppable" ).droppable( "widget" );
Fires when an acceptable draggable begins dragging.
$( "#droppable" ).droppable({
activate: function ( event, ui ) {
console.log( "activate" );
}
});
Fires when Droppable is initialized.
$( "#droppable" ).droppable({
create: function ( event, ui ) {
console.log( "create" );
}
});
Fires when an acceptable draggable stops dragging.
$( "#droppable" ).droppable({
deactivate: function ( event, ui ) {
console.log( "deactivate" );
}
});
Fires when an accepted draggable is dropped on the target.
$( "#droppable" ).droppable({
drop: function ( event, ui ) {
console.log( "drop" );
}
});
drop: function ( event, ui ) {
$( this ).text(
"Dropped: " + ui.draggable.text()
);
}
Fires when an accepted draggable leaves the target.
$( "#droppable" ).droppable({
out: function ( event, ui ) {
console.log( "out" );
}
});
Fires when an accepted draggable enters the target.
$( "#droppable" ).droppable({
over: function ( event, ui ) {
console.log( "over" );
}
});
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.