I have a nice solution from my previous question that successfully clones images after being dropped.
Here is the code:
$(function() {
var makeDraggable = function(element) {
element.draggable({
revert: "invalid",
appendTo: "#droppable",
helper: "clone"
});
}
$( "#droppable" ).droppable({
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
var newClone = $(ui.helper).clone();
makeDraggable(newClone);
$(this).after(newClone);
}
});
// Initalise the program by making first draggable:
makeDraggable($(".draggable img"));
But the problem is I want to show only one image at a time in the targeted area. But currently all the dropped images are shown.
More specifically when user drops an image in the targeted area and later drags another image, the previous image should be removed from the dropped or targeted area and only the new image should be visible in the targeted area. See this demo: jsFiddle example
How do I solve this?