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 :)
Check whether your draggable object is already loaded in the viewport. If it is not, it won't work properly. JUST AFTER the draggable object to be absolutely sure that everything is loaded at the correct time. When you'll be sure everything is ok, then you'll be able to refactor.
Syntax: $( ". selector" ). draggable({ disabled: true/false });
jQuery UI draggable() method is used to make any DOM element draggable. Once the element is made draggable, you can move it by clicking on it with the mouse and drag it anywhere within the viewport.
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. If the value of this option is set to false, it will prevent the DOM elements to be dragged .
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.
I was able to recreate your scenario in this jsfiddle:
http://jsfiddle.net/dboots/NDZKY/
This is using
$('.draggable').draggable('disable');
and
$('.draggable').draggable('enable');
Is there something different that you're not able to do the same? Looks like you have the same syntax.
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