I've got a bunch of elements with jQuery. Some are draggable, some are droppable and some are both. How can I detect if an element is draggable or droppable?
The draggable (option) method specifies that an HTML element can be moved in the HTML page. Here, the option parameter specifies the behavior of the elements involved. Syntax: $(selector, context).
Draggable() Method This method allows the elements to be dragged with the help of mouse. Using jQuery UI, we can make the DOM(Document Object Model) elements to drag anywhere within the view port. This can be done by clicking on the draggable object by mouse and dragging it anywhere within the view port.
You have one of these problems: Your jQuery or jQuery UI Javascript path files are wrong. Your jQuery UI does not include draggable. Your jQuery or jQuery UI Javascript files are corrupted.
You could also use jQuery data()
like this..
if ($(elem).data('draggable')) { alert("yes"); } else { alert("no"); } if ($(elem).data('fooable')) { alert("yes"); } else { alert("no"); }
See it here: http://bootply.com/60153
This works for me with JQuery 1.10.2
if ($("el").data('uiDraggable')){ //or uiDroppable alert("draggable") } else { alert("not draggable") }
Alternatively it is possible to invoke .data() method without argument
$("el").data()
That should print something like
Object {uiDraggable: $.(anonymous function).(anonymous function)}
where you can see object properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With