下面的代码尝试让 btn mousedown 找到父兄弟姐妹(img_wp)img,但它不起作用。我的代码在某个地方错了?
$('.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>