I’m really new in JS and JQuery and I’m failing in select a element to animate, this is my HTML
<div class="box-product">
<h2>Light</h2>
<figure>
<img src="img/boxes/light.jpg" alt="Pepper Box Light" title="Pepper Box Light" />
<figcaption>
Versão light, porém igualmente apimentada da nossa PepperBox, para quem quer se divertir com seu amor</figcaption>
</figure>
</div><!-- box-product -->
I’m trying to select the h2 when the user hover the figure, so that’s my best guess:
$('.box-product figure').hover(function() {
$('.box-product').closest('h2').animate({color: 'f00'}, 'slow')
}, function() {
$('.box-product').closest('h2').animate({color: 'inherit'}, 'slow')
});
But nothing happens, so, I need some help.
Thanks!
closest():You can use
prev()method:or: