Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if an element is droppable, draggable or other 'ble'?

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?

like image 428
Kees C. Bakker Avatar asked Nov 21 '11 18:11

Kees C. Bakker


People also ask

What is the syntax of the draggable function?

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).

What is jQuery draggable?

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.

Why is draggable not working?

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.


2 Answers

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

like image 149
Zim Avatar answered Sep 23 '22 20:09

Zim


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.

like image 31
humkins Avatar answered Sep 22 '22 20:09

humkins