Alko Alko - 6 days ago 4
jQuery Question

jQuery sortable, on receive unwrap() element

I'm using jQuery Sortable to sort items in connected list. Using receive() event I want to unwrap() element, before is dropped onto list.

<div id="main">

</div>

<div id="side">
<div class="element">
<div class="row">Item 1</div>
</div>
</div>

$("#main").sortable({
receive: function( event, ui ) {
$(ui.item).unwrap();
}
});

$("#side").sortable({
connectWith: "#main"
});


But for some reason as soon as item is dropped onto a #main list, main element is removed.

Answer

At that time, ui.item is a child of #main. Unwrapping .element will not remove #main:

$(ui.item).children('.element:first').unwrap();
Comments