JQuery UI Draggable - How do I know if an item is being dragged initialized?

My logic

if( !this.draginited() ) // a drag-disabled element shouldn't get pass here, as it is inited
  this.draggable({...})

I searched a lot and could not find a way to implement this logic, any ideas?

+5
source share
2 answers

There may be an easier way, but the docs say:

Dragable items get the class u-dragable

so you can do something like:

if(!$("#foo").hasClass("ui-draggable")) {
    ...
}

to wrap this (untested):

$.fn.isDraggable = function() {
    return $(this).hasClass("ui-draggable");
}

console.log($("#someElement").isDraggable());
+12
source

The event is dragstartfired when the drag and drop starts. More in docs

0
source

All Articles