views:

32

answers:

1

Any ideas on how to make the clones draggable?

            $("#draggable").draggable({
                helper: 'clone',
                cursor: 'pointer',
            });

            $("#snaptarget").droppable({
                drop: function(event, ui) {
                       var randomnumber = Math.floor(Math.random()*1000000);
                       var newId = '#draggable_'+randomnumber;

                        $(ui.helper).clone(true).removeAttr('id').attr('id',newId).appendTo('#snaptarget');                     
                        $(newId).draggable();                   
                }
            });

$(newId).draggable(); does not work.

+2  A: 

You can't start IDs with a #. As you are here:

var newId = '#draggable_'+randomnumber;

It should be:

var newId = 'draggable_'+randomnumber;

Then this:

$(newId).draggable();

should be:

$('#' + newId).draggable();

Example: http://jsfiddle.net/M3UWp/

So you end up with:

var newId = 'draggable_'+randomnumber;
$(ui.helper).clone(true).removeAttr('id').attr('id',newId).appendTo('#snaptarget');  
$('#' + newId).draggable();                   
patrick dw
That worked perfectly, thanks.
jbatson
One more question, how do i stop the cloning of the cloned item, just need it to be draggable.
jbatson
I am trying to do something like http://examples.placona.co.uk/drag_drop except with the latest version of jquery.
jbatson
@jbatson - I don't know much about draggable, but I took a quick look at the docs, and moved your code into the `stop:` callback of `draggable`. Seems to work. See it here: http://jsfiddle.net/M3UWp/1/
patrick dw
@jbatson - ...also, don't forget to click the checkmark next to this answer if you found it helpful. :o)
patrick dw
That works perfectly, thanks for taking the time to answer, many thanks....
jbatson