EasyUI Forum
September 13, 2025, 11:51:13 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: bind drag event to cloned element [solved]  (Read 7467 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« on: November 13, 2014, 06:57:26 PM »

I am using drag and drop and need to clone the dropped element several times after it has been dropped.

If I use the jquery clone(true) method on the dropped element, then the element gets cloned, however the draggable event does not get bound to the cloned elements.

How can I bind an existing draggable() function to elements that are added dynamically ?

I have tried adding the 'draggable' class to the cloned element but that does not appear to work ?

Code:
....
onDrop: function(e,src){
  $src).detach().appendTo(td).css({'position':'','left':'','top':''});
  $('xxx').append($(src).clone(true))
}
« Last Edit: November 14, 2014, 11:59:03 PM by devnull » Logged

-- Licensed User --
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: November 13, 2014, 09:57:41 PM »

After cloned a object successfully, you must call .draggable(...) to make it draggable again.
Code:
onDrop: function(e,src){
  $src).detach().appendTo(td).css({'position':'','left':'','top':''});
  var obj = $(src).clone(true).appendTo('xxx');
  obj.draggable({...})
}
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!