below code try to make if btn mousedown find parent siblings(img_wp) img, but it doesn’t work. my code wrong in somewhere?
$('.btn').mousedown(function(e){
var target_img = $(e.target).parent().closest('.img_wp img');
var target_img_w = target_img.width();
var target_img_h = target_img.height();
console.log(target_img_w + target_img_h);
});
<div class=\"wp\">
<div class="img_wp">
<img>
</div>
<div class="btn_wp">
<div class="btn"></div>
</div>
</div>
<div class=\"wp\">
<div class="img_wp">
<img>
</div>
<div class="btn_wp">
<div class="btn"></div>
</div>
</div>
.closest()looks for the closest ancestor with a matching selector. Since your button’s parent has noimgancestor, your selector returns an empty set.Use this instead: