Reputation: 620
I have the following:
$(".myclass").sortable();
$("#mydiv").droppable({
drop: function( event, ui ) {
$(this).append( "<div>Test</div>" );
}
});
After I drop on #mydiv it appends the div as expected,but when I use the sortable and drop again it appends another div. What would be a better way to do this?
Upvotes: 1
Views: 204
Reputation: 30993
You can check if the dropped element is coming from a draggable or a sortable. To do so you can check if the element have the ui-draggable
class, if not exit you function.
Code:
$("#mydiv").droppable({
drop: function (event, ui) {
if (!ui.draggable.hasClass('ui-draggable')) return
$(this).append("<div>Test</div>");
}
});
Demo: http://jsfiddle.net/IrvinDominin/hsTFN/
Upvotes: 1