Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Show Class on hover issue

Tags:

jquery

I am trying to get a div to show when a link is hovered.

There will be multiple classes too so only the nearest should show.

This is what I'm trying:

$(".box").hover(function() {
    $('.overlay').closest.show();
});

<div class="event" id="selector">                                       
    <a class="box" href="#" title="">Event</a>      
    <div class="overlayOuter">    
        <div class="overlayInner"></div>    
    </div>    
    <div class="overlay" style="display:none;"> I will come out when class Box is covered 
    </div>    
</div>  

When I hover class="box" then class="overlay" is shown.

The problem is that Overlay is not appearing so I'm guessing my jquery is wrong?

How can I get this to work?

like image 563
Satch3000 Avatar asked Feb 27 '26 20:02

Satch3000


2 Answers

Try this, overlay is not a parent it is a sibling, closest() gets the closest parent

   $(this).siblings('.overlay').show();
like image 100
Anton Avatar answered Mar 01 '26 10:03

Anton


Try this:

$(this).siblings('.overlay').show();
like image 42
Greenhorn Avatar answered Mar 01 '26 09:03

Greenhorn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!