Reputation: 1859
I am having 2 UL and one button
<ul class="droptrue ui-sortable" id="sortable1" style="min-height: 128px; mozuserselect: none;"
unselectable="on">
<li id="article_1" class="ui-state-default">
<input type="checkbox" id="1" />
Article #1</li>
<li id="article_2" class="ui-state-default">
<input type="checkbox" id="2" />
Article #2</li>
<li id="article_3" class="ui-state-default">
<input type="checkbox" id="3" />
Article #3</li>
</ul>
<ul class="droptrue ui-sortable" id="sortable2" style="min-height: 128px; mozuserselect: none;"
unselectable="on">
<li id="article_4" class="ui-state-default">
<input type="checkbox" id="4" />
Article #4</li>
<li id="article_5" class="ui-state-default">
<input type="checkbox" id="5" />
Article #5</li>
<li id="article_6" class="ui-state-default">
<input type="checkbox" id="6" />
Article #6</li>
</ul>
<input type="button" id="add" value=">>" style="width: 15px" onclick="AddToList()" />
now on button click i need to remove the corresponding li form "sortable1" and insert it into "sortable2"
I wrote the function like
function AddToList() {
var vals = $('#sortable1 input:checkbox:checked').map(
function() {
$("#sortable2").append($(this).parent().html());
$(this).parent().remove();
return this.id;
}).get().join(',');
}
but this function removes the li but adding only the checkbox into the other ul. if i give $(this).parent().parent().html() which adds all the li to the other ul.Please tell me what i am missing here?
Upvotes: 0
Views: 485
Reputation: 144659
Use appendTo
method.
var vals = $('#sortable1 input[type=checkbox]:checked').map(function() {
$(this).parent().appendTo('#sortable2');
return this.id;
}).get().join(',');
Upvotes: 1