如何完全删除列表项及其内容?

And*_*jal 0 javascript jquery

我无法删除li和html内容,我的html看起来像:

<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>
Run Code Online (Sandbox Code Playgroud)

删除操作取决于单击具有图像名称的按钮.

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

    });
Run Code Online (Sandbox Code Playgroud)

epa*_*llo 7

问题是prev()兄弟姐妹,而不是父母.您需要选择父母才能到达li.

$('img[name="'+id_img+'"]').parent().parent().remove();
Run Code Online (Sandbox Code Playgroud)

要么

$('img[name="'+id_img+'"]').closest("li").remove();
Run Code Online (Sandbox Code Playgroud)