Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQUERY if not hover

Tags:

jquery

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
    });
like image 521
s15199d Avatar asked May 07 '10 13:05

s15199d


1 Answers

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();
    }
});
like image 65
Sam Avatar answered Sep 17 '22 20:09

Sam