I have an element which needs to drop into droppable(Jquery UI droppable
) div while drag and drop(works perfect), but i need to drop the same element while onclick on it.
Reason why i need the above said functionality: The code gets repeat while used separate code to clone and append the element into droppable div when onclick. I need to use same code for both. How to pass the onclicked element (draggable element) into drop function.?
$(document).ready(function()
{
var cloned_element;
$("#draggable").draggable({
helper: 'clone',
revert: true
});
$("#droppable").droppable(
{
drop: function(event, ui)
{
cloned_element = $(ui.helper).clone();
ui.helper.remove();
cloned_element.appendTo(this);
$(this).addClass("ui-state-highlight").find("p").html("Dropped!");
}
});
$('#draggable').on('click',function()
{
$(this).trigger("drop", $('#droppable'));
});
});
Sample code in Jsfiddle..!