You need a droppable method to detect the difference between a discarded external hedgehog and one of the discarded hedgehogs. This way you can make sure that the drop callback only clones the hedgehogs that have been reset from the outside.
Conveniently enough, you already have a way to detect this: <img> has an identifier outside the field, and there are no elements within the field in discarded <img> elements. So, all you have to do is figure out how to access the “source” dropable element inside the drop callback function.
According to droppable docs, ui.draggable is "the current drag and drop element, jQuery object", so you can get this id element in any of several ways. Here is one way:
$("#draggable1").draggable({ helper: 'clone', revert: "invalid" }); $("#panel1").droppable({ drop: function(event, ui) { if (ui.draggable[0].id) { $(this).append($(ui.helper).clone().draggable()); } } });
Demo: http://jsfiddle.net/mattball/MJhcp/
Since ui.draggable is a full-blown jQuery object, it will also work to use any of the following, instead of ui.draggable[0].id :
ui.draggable.get(0).idui.draggable.attr('id')ui.draggable.prop('id')
source share