Remove parent div by class name - jquery

前端 未结 5 1523
别那么骄傲
别那么骄傲 2021-01-14 20:58

I have a remove link that will remove the current comment on my page. It uses ajax to change the database and upon success, I want to remove the div the comment resides in.

5条回答
  •  迷失自我
    2021-01-14 21:57

    Use closest():

    $(this).closest(".aComment").remove();
    

    Example.

    The parent of the a tag is the span. The div you are trying to remove is the parent of that span.

    The reason for using this is simply because it's more convenient than using parent() twice.

提交回复
热议问题