Removing empty space with jQuery after deleting Selectable item
Posted
by Tx3
on Stack Overflow
See other posts from Stack Overflow
or by Tx3
Published on 2010-05-07T06:29:39Z
Indexed on
2010/05/07
7:28 UTC
Read the original article
Hit count: 243
I have two ordered lists and user can move items between them. I am using jQuery UI's Selectable for both of them. Problem is that when I move item from the middle of the list it leaves an empty space behind. How can I make list shrink according to the how many items is actually in the list?
HTML
<ol id="allUnits">
<li class="ui-state-default">Item 1</li>
<li class="ui-state-default">Item 2</li>
<li class="ui-state-default">Item 3</li>
<li class="ui-state-default">Item 4</li>
<li class="ui-state-default">Item 5</li>
</ol>
<input id="arrowRight" type="image" alt="Move item to right" src="<%= Url.Content("~/Content/Images/arrowRight.png")%>" />
<input id="arrowLeft" type="image" alt="Move item to left" src="<%= Url.Content("~/Content/Images/arrowLeft.png")%>" />
<ol id="productUnits">
<li class="ui-state-default">Item 1</li>
<li class="ui-state-default">Item 2</li>
<li class="ui-state-default">Item 3</li>
<li class="ui-state-default">Item 4</li>
<li class="ui-state-default">Item 5</li>
</ol>
jQuery
$().ready(function () {
$("#allUnits").selectable();
$("#productUnits").selectable();
$('#arrowRight').click(function () {
return !$('#allUnits .ui-selected').remove().appendTo('#productUnits').removeClass(".ui-selected");
});
$('#arrowLeft').click(function () {
return !$('#productUnits .ui-selected').remove().appendTo('#allUnits').removeClass(".ui-selected");
});
});
© Stack Overflow or respective owner