jquery draggable enable and disable

Gleiemeister 2000 picture Gleiemeister 2000 · Nov 29, 2012 · Viewed 37.4k times · Source

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

Barmar picture Barmar · Nov 29, 2012

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.