See http://jsfiddle.net/Vk5zT/7/:
$(this).replaceWith($(draggedItem).clone(true,true));
$(draggedItem).replaceWith($(this).clone(true,true));
But .clone(true,true)
should copy the event listeners too, but it doesn't, so drag and drop stops working. I solved it creating the function addEvents
:
function addEvents(){
$('.segmentListItem').each(function(index){
$(this)[0].addEventListener('dragstart',handleDragStart,false);
$(this)[0].addEventListener('drop',handleDrop,false);
$(this)[0].addEventListener('dragover',handleDragOver,false);
});
}
and then:
$(this).replaceWith($(draggedItem).clone(true,true));
$(draggedItem).replaceWith($(this).clone(true,true));
addEvents();
Edit:
I have fixed the problem with event listeners, and I have adapted your code to jquery:
http://jsfiddle.net/Vk5zT/12/