使用jquery删除父div

时间:2013-04-09 01:56:58

标签: jquery html html5 jquery-mobile

我有一个旨在删除父div的jquery脚本。但是,删除按钮不会显示为按钮,也不会删除父div。我正在使用jQuery Mobile。

这是jquery:

 $(".delete_content").click(function() { 
    $(this).closest(".content_container").remove();   
   });

这是html:

<div class='content_container'>
      <a class='delete_content' data-role='button' data-icon='delete' data-inline='true' data-iconpos='right'>
            Delete
      </a>
</div>

1 个答案:

答案 0 :(得分:3)

$(".delete_content").click(function() { 
    $(this).parents(".content_container").remove();   
});

您需要使用.parents而不是.closest