我試圖在懸停到使用jQuery的元素上添加CSS類。然而,類應該只讓我嘗試使用.next
使用jQuery在懸停上添加CSS類
當我加入.next
我的代碼,雖然該類不再添加應用到最接近的元素與特定的類(它的工作原理沒有那部分代碼)。這是代碼:
$j('.products_overlay').hover(function(){
$j(this).next('.hover_text').addClass('overlay_text');
}, function(){
$j(this).next('.hover_text').removeClass('overlay_text');
});
任何想法我做錯了什麼?
這是HTML
<div class="products_overlay">
<a href="..." title="product1" class="product-image">
<img src="...." alt="product1" class="hover_test" />
</a>
<p class="hover_text">Test</p>
</div>
你的HTML,好嗎? – nicael
某些片段或小提琴? – RaV
聽起來像'.hover_text'不是'.products_overlay'的兄弟,所以'next()'不會找到它。我們需要看到你的HTML能夠幫助你修復這個 –