所以我的 php 结构如下:
<div class="top">
<div class="middle">
<?php echo '<a class="delete" data-post_id="' .$id. '">' ?>
<div class="delete_button">Delete</div>
</a>
</div>
</div>
<!--Different post -->
<div class="top">
<div class="middle">
<?php echo '<a class="delete" data-post_id="' .$id. '">' ?>
<div class="delete_button">Delete</div>
</a>
</div>
</div>
然后是js。
jQuery('.delete').live('click',function(){
var post_id = jQuery(this).data("post_id");
var post = jQuery(this).parent(); //????????
jQuery.ajax({
type : 'POST',
url : custom.ajax_url,
data : { 'action':'deletePost' , post_id:post_id},
success : function(data){
post.fadeOut();
}
});
});
因此,如您所见,我有两个具有不同 post_id
的 div 容器。
使用 js,我想将特定的“top
”div 设为淡出目标。
我有 var post = jQuery(this).parent();
对吗?
谢谢
最佳答案
你可以使用
jQuery(this).parents('.top');
或
jQuery(this).closest('.top');
关于javascript - 特定 div 的 jQuery 父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33970808/