Andres Carvajal Andres Carvajal - 22 days ago 12
jQuery Question

How can I completely remove a list item and its content?

i canĀ“t remove li and html content, my html looks like:

<li>
<a href="#dialog-form-image" rel="modal:open">
<img src="http://www.miapp.cl/walmart/admincontenidoatg/wp-content/themes/admincontent/images/imagen_wf.jpg" name="img_164" id="flexslider">
</a>
</li>


Remove action depend click a button with name of image.

$("#btn-url-delete").live('click',function(){
var id_img = $(this).attr("name");
$('img[name="'+id_img+'"]').prev().prev().remove();
$(this).remove();

});

Answer

The problem is prev() is siblings, not the parent. You need to select the parents to get to the li.

$('img[name="'+id_img+'"]').parent().parent().remove();

or

$('img[name="'+id_img+'"]').closest("li").remove();