大家好,当我单击删除带有 shared_box 类的框时,我有这种元素结构应该隐藏它。我试图用 parent() 和最接近的方法来做,但没有用。这是我的计划。
<div class="shared_box"> <!--Element to hide -->
<div class="user_post">
<img src="#" class="pull-left">
<!-- Single button -->
<div class="btn-group pull-right action_post" style="display: block;">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<!-- element clicked -->
<li><a href="#" class="delete" id="13">Delete</a></li>
<li><a href="#">Hide Post</a></li>
</ul>
</div>
</div>
</div>
编辑
JS
$(document).on("click", ".delete", function() {
var id_post = $(this);
bootbox.confirm("Are you sure do want delete?", function(result) {
if (result) {
$.ajax({
type: "POST",
dataType: "json",
url: CI_ROOT + 'delete_post',
data: "id_post=" + id_post.attr('id') ,
success: function(val) {
id_post.closest('div.shared_box').hide();
// this one doesn't work
}
});
} else {
console.log("close");
}
});
});