Draggable Clones Jquery?
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;
$开发者_JAVA技巧(ui.helper).clone(true).removeAttr('id').attr('id',newId).appendTo('#snaptarget');
$(newId).draggable();
}
});
$(newId).draggable(); does not work.
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();
精彩评论