How to auto apply drag and drop effect to dynamically added element?

前端 未结 3 748
Happy的楠姐
Happy的楠姐 2021-01-27 16:51

I use jquery ui to apply a drag and drop effect on a serial of DIVs, for example:

...
.
相关标签:
3条回答
  • 2021-01-27 17:29

    Have a look at the jQuery .live(). I believe you could use it here. If not - just attach .draggable() when you create your element.

    0 讨论(0)
  • 2021-01-27 17:40

    You cannot use the .live() function with .draggable() directly, but you can use .live() with the mouseover event and re-attach .draggable() on mouseover like this.

    $('.draggable').live('mouseover',function(){
        $(this).draggable();
    });
    
    0 讨论(0)
  • 2021-01-27 17:45

    You might also like to take a loot at the delegate() method introduced with jQuery 1.4 which is slightly better than live()

    Here is an article comparing both approaches - http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-the-difference-between-live-and-delegate/

    0 讨论(0)
提交回复
热议问题