JQuery How to use .live on draggable

I am using the dragabble method from jquery ui. How to apply live () to drag and drop.

$("#image").draggable({ containment: [10, 150, 0, 0], scroll: false}); 

What i tried is

 $("#image").live("draggable", function () { .draggable({ containment: [10, 150, 0, 0], scroll: false}); 

But that does not work.

thanks

+7
source share
1 answer

First, as FYI, live is deprecated, you should use .on () as comments above the state.

Secondly, you will not be able to do what you need to do with any script, since these events are not baked into on (). Therefore, the way I would like to approach it is to bind your event inside the function:

 function doDraggable() { $(".draggable").draggable({ containment: [0, finalHeight, 0, 0], scroll: false}); } 

Then initialize it when the document is ready, and also whenever ajax completes:

 $(document).ready(function () { doDraggable(); }); $(document).ajaxComplete(function () { doDraggable(); }); 

You can be more specific than a document selector using the ajaxComplete event so that it doesn't fire for every ajax event, but you get my drift ...

+14
source

All Articles