kidwon
kidwon

Reputation: 4524

Tell if jQuery DOM element is draggable or not

Does jQuery UI store any properties to a jQuery dom ref element?

What I'm particular interested in is any data or properties or function that can tell is it draggable?

Example:

var jqnode = jQuery('selector');
jqnode.draggable({...});
var isDraggable = !!(jqnode.tellIsDraggableProperty);

Upvotes: 0

Views: 83

Answers (3)

Esailija
Esailija

Reputation: 140220

var isDraggable = !!jqnode.data("draggable")

or

var isDraggable = jqnode.is(":ui-draggable");

Depending on what you want to do, you could use the selector in the original:

jQuery('selector:ui-draggable').fn()

This would neatly only call fn if it was draggable.

Upvotes: 3

Joseph Silber
Joseph Silber

Reputation: 219938

When jQueryUI initializes the draggable, it add a ui-draggable class to the element:

var isDraggable = jqnode.hasClass('ui-draggable');

Upvotes: 1

crush
crush

Reputation: 17013

I think this will do what you ask if I understand correctly.

var jqnode = jQuery('selector');
var isDraggable = (typeof jqnode.draggable === 'function');

Also, I think hasOwnProperty() would work too:

var jqnode = jQuery('selector');
var isDraggable = jqnode.hasOwnProperty('draggable');

Upvotes: 1

Related Questions