How do I programmatically abort a jQuery drag operation?

remack picture remack · Jan 28, 2011 · Viewed 7.4k times · Source

How do I programmatically abort a jQuery drag operation?

Using jQuery UI, the user begins a drag operation. While dragging, an asynchronous event occurs that causes the dragged element to be deleted (a timer-based refresh, for example). In the refresh, I would like to do something like this before the refresh to avoid errors from the deleted element :

   element.trigger('dragstop');

But that didn't seem to work.

Answer

FerRory picture FerRory · Jan 28, 2011

This can be done by using the callback function (returning false) of the drag or drop event. See http://jqueryui.com/demos/draggable/#event-drag