Skip to content

Instantly share code, notes, and snippets.

@rafarubert
Created July 3, 2011 05:34
Show Gist options
  • Save rafarubert/1061978 to your computer and use it in GitHub Desktop.
Save rafarubert/1061978 to your computer and use it in GitHub Desktop.
$(function(){
var _new_li = new String();
var _element = new Object();
$( "#draggable > li" ).draggable({ revert: true });
$( "#droppable").droppable({
accept: "#draggable > li",
drop: function(event, ui){
console.log(ui);
_new_li = $('<li>'+ui.draggable.context.innerHTML+'<input name="campaign[employee_ids][]" type="hidden" value="'+ui.draggable.context.id+'" /> <span><img src="/assets/cancel.jpg" alt="Remover" title="Remover"></span></li>')
.attr('id', ui.draggable.context.id);
$('#droppable').append(_new_li);
$(ui.draggable).remove();
}
});
$("#droppable > li > span").live("click", function(event){
var _element = $(this).parent();
_element.children().remove();
_new_li = $("<li>"+_element.text()+"</li>").attr('id', _element.attr('id')).attr('class', 'draggable');
_new_li.draggable({ revert: true });
$("#draggable").append(_new_li);
_element.remove();
});
});
@md2perpe
Copy link

md2perpe commented Jul 3, 2011

But you overwrite the values of _new_li on lines 10 and 24, and of _element on line 20. The String and Object are thrown away there. And I don't see any need for the variables to be actually instatiated in other places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment