How do you delete an item from a 'this' object in a jQuery function?
I am trying to delete an <li>
item using the this.remove() function but I can't find the function in the DOM using Firebug:
jQuery
$( "#list_a, #list_b" ).sortable({
connectWith: ".connected_sortable",
receive: function(event, ui) {
$("#list_b li").each(function() {
if(ui.item.context.id == this.id)
$(this).remove(); //<-----HOW DO I DELETE? (also tried this.remove())
});}}}).disableSelection();
HTML
<ul id="list_a" class="connected_sortable">
<li id="item_1">test text</li>
<li id="item_3">test text</li>
<li id="item_4">test text</li>
</ul>
<ul id="list_b" class="connected_sortable">
<li id="item_3">test text</li>
</ul>
How would I go about deleting an <li&开发者_开发百科gt;
here? Please do not give me a direct reference solution - eg $("#item_3").remove()
because I am trying to delete the other similiar id <li>
.
I think this should work.
$('#list_b li[id="'+ ui.item.context.id +'"]').remove();
this should replace the .each loop you have btw:
also, you should use $(this).attr("id")
instead of this.id
assuming you meant the jQuery element when y9ou said this
, but try the above first me thinks.
also look at this question JQuery. Remove element by attribute name. How?
精彩评论