Gleiemeister 2000 Gleiemeister 2000 - 1 month ago 7
jQuery Question

jquery draggable enable and disable

Ive tried anything to do this, but always get the same error

$(".tooltip").draggable('disable');


Error: cannot call methods on draggable prior to initialization; attempted to call method 'disable'

Prior to initialization? So I cannot remove the option before its actually being dragged around? Ive tried with droppable as well, cant seem to get them disabled enabled without getting this error.

edit:
I found out that I have an element with the class that is without draggable (which makes sense when you look at the error). Now I just have to find a way so it disables all the draggables without throwing the error :)

Answer

Try this:

$(".tooltip").draggable({ disabled: true });

This initializes the draggable in the disabled state. You can then use

$(".tooltip").draggable("enable");

later when you want to allow dragging.