I'm trying to add a CSS class on hover to an element using jQuery. However, the class should only be applied to the closest element with a specific class so I tried using .next
When I add the .next to my code though the class isn't added anymore (it works without that part of the code). This is the code:
$j('.products_overlay').hover(function(){
$j(this).next('.hover_text').addClass('overlay_text');
}, function(){
$j(this).next('.hover_text').removeClass('overlay_text');
});
Any idea what I'm doing wrong?
This is the 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>
.hover_textis not a sibling of.products_overlaysonext()won't find it. We need to see your HTML to be able to help you fix this$j(this).parent().find('.hover_text')