我想找到最接近H2標籤懸停的圖像下面是我的HTML代碼jQuery的:尋找最接近的H2標籤
<div class="col-md-3 col-sm-3 col-xs-12" style="padding-left:0;">
<div class="ih-item square effect7"><a href="#">
<div class="img">
<img src="images/facilities/facility1.png" class="img-responsive fullwidthimg">
</div>
<div class="info">
<h3>Content </h3>
<p>Some content </p>
</div></a>
</div>
<h2>Arenas</h2>
</div>
這就是我試圖在jQuery的做
$(document).ready(function() {
$('.img').hover(function(){
$(this).closest('h2').hide();
})
})
請幫助我如何做到這一點。
改變你的代碼,這個'$(本).closest( 'H2')隱藏();',你需要包括在CSS選擇單/雙qoutes您的標籤去工作 –
[查找具有特定類的最接近的祖先元素]的可能重複(https://stackoverflow.com/questions/22119673/find-the-closest-ancestor-element-that-has-a-specific-class ) – Rob
https://stackoverflow.com/questions/16194578/find-closest-element-in-complete-document – Rob