I am looking to implement a mouse hover effect in my product section, where each image should display its title only when hovered over. Currently, all titles are being shown on mouseover, which is not the desired behavior.
The following code works for mouseover events but it applies the 'highlight' class to all elements. I want the script to only apply the 'highlight' class to the specific element being hovered over, such as the first div with the class='top-section'.
HTML
<div class ="featured">
<div class="featured-section">
<a href="#" class="featured-link">
<div class="top-section">
<img src="1.jpeg">
<span class="highlight">
<h3 class="title">title 1</h3>
</span>
</div>
</a>
</div>
<div class="featured-section">
<a href="#" class="featured-link">
<div class="top-section">
<img src="2.jpeg">
<span class="highlight">
<h3 class="title">title 2</h3>
</span>
</div>
</a>
</div>
<div class="featured-section">
<a href="#" class="featured-link">
<div class="top-section">
<img src="3.jpeg">
<span class="highlight">
<h3 class="title">title 3</h3>
</span>
</div>
</a>
</div>
</div>
Script
$(".top-section").on({
mouseenter: function () {
$(this).find(".highlight").addClass("show").fadeIn();
},
mouseleave: function () {
$(this).find('.highlight').removeClass("show").fadeOut();
}
});