With jQuery UI, is it possible to execute a drag & drop operation using javascript?
Example. When the link is clicked, drag the #pony
and drop it into the #box
. I've tried triggering the drag event but that doesn't seem work :)
$('#pony').trigger('drag', [$('#box')]);
This is how the jQuery UI team programmatically trigger
drop
event.droppable_events.js:
The
simulate
function is defined in jquery.simulate.js. In simple words, it moves the draggable onto the droppable to trigger thedrop
event.Putting this altogether, we have the following snippet. Cheers.
If you want to fire the same functionality that happens when you actually do drop the object by mouse, you can encapsulate your drop script into a function that you then can simply call elsewhere, too.
If you want to have an animated motion of your item being dragged & dropped, you should
.stop().animate({})
it to the target position, followed by the step above.If you simply want to append it to the drop target, just
.appendTo($('#yourtargetid'));
.Sorry if I missunderstood anything, my reputation points aint enough to just ask you beforehand as I'd have done everywhere else.