我有一个旨在删除父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>
答案 0 :(得分:3)
$(".delete_content").click(function() {
$(this).parents(".content_container").remove();
});
您需要使用.parents
而不是.closest