I want to:
- Make the draggable element drop in a container.
- Change the elements html when dropped.
- When the dropped element is dragged outside the container, revert to the original position and also revert to old html.
My current problems
- While the draggable element is hovering the container, it already changes its style.
- I can't understand how can I achieve 'dropped element revert to original position' (point 3 @ "I want to")
JSFiddle
HTML
<div class="draggable-items">
<div class="main-groups">Item 1</div>
<div class="main-groups">Item 2</div>
<div class="main-groups">Item 3</div>
<div class="main-groups">Item 4</div>
</div>
<div id="container"></div>
jQuery
$(function() {
$( ".main-groups" ).draggable({
connectToSortable: "#container",
helper: "original",
revert: "invalid"
});
$( "#container" ).sortable({
revert: true,
receive: function(event, ui) {
var html = [];
$(this).find('.main-groups').each(function() {
html.push('<div class="main-groups"><b><a href="#'+$(this).attr("id")+'">'+$(this).html()+'</a></b></div>');
});
$(this).find('.main-groups').replaceWith(html.join(''));
}
});
});