15

Mouseenter of DIV A sets DIV B to show(). What I want is on mouseleave of DIV A if they are not hovering over DIV B, hide DIV B. But, on mouseleave of DIV A if they are hovering over DIV B keep showing DIV B.

$('#DIVA').mouseenter(function() {
        $('#DIVB').show();  
    }).mouseleave(function() {      
        //if DIVB not hovering
            $('#DIVB').hide();
        //end if
    });
1
  • Can you show the markup? Commented May 7, 2010 at 13:48

2 Answers 2

16

Could you add a class to #DIVB on hover then check for it on mouseleave for #DIVA?

$('#DIVB').hover(function(){
    $(this).addClass('active');
}, function(){
    $(this).removeClass('active');
})

$('#DIVA').mouseenter(function() {
    $('#DIVB').show();  
}).mouseleave(function() {      
    if(!$('#DIVB').hasClass('active')){
        $('#DIVB').hide();
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

I actually used bits of both of your solutions. Thank you both!
7

It could be as simple as just using hover.

http://jsbin.com/ojipu/2

...but that depends on what the markup looks like.

3 Comments

It relies on Div B using the same space as Div A, what if they have distance between them?
I'm not sure how you would leave Div A and still know to show Div B if they didn't overlap.
I had the same problem. Check this: stackoverflow.com/questions/6645551/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.