Edward
Edward

Reputation: 4918

JQuery UI Draggable - How to know an element is draggable initialized?

My logic is

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

I searched a lot and couldn't find a way to implement this logic, any ideas?

Upvotes: 5

Views: 2043

Answers (2)

Quasipickle
Quasipickle

Reputation: 4498

The dragstart event is fired when dragging is started. More in the docs

Upvotes: 0

karim79
karim79

Reputation: 342635

Maybe there's an easier way, but the docs say:

Draggable elements gets a class of ui-draggable

so you could do something like:

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

so to wrap that up (untested):

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

console.log($("#someElement").isDraggable());

Upvotes: 12

Related Questions