Jquery if condition on mouse leave or mouse enter

Hello People here is my jquery code.

$(val1+","+val2).mouseleave(function(){

    $('.opacity').remove();
    $(val3).show();
    $(val4).hide();

});

i want to edit this code in such a way that after

$(val1+","+val2).mouseleave(function(){
    if mouse doe not  enter val3 or val4
then 
    $('.opacity').remove();
$(val3).show();
$(val4).hide();
else
    nothing....

something like ...

$(val1 + "," + val2).mouseleave(function() {

    if ($(val3 + "," + val4).mouseenter) {
    } else {
        $('.opacity').remove();
        $(val3).show();
        $(val4).hide();
    }

});

obviously above does not work ... iam wrong somewhere near if condition how to fix this?

Answers:

Answer

You should play with a variable updated according to the mouseenter and mouseleave information about val3 and val4

var isHoverSpecialDiv = false;

$(val3 + "," + val4).hover(
    function(){
        isHoverSpecialDiv = true;
    },
    function(){
        isHoverSpecialDiv = false;
    }
});

And test it

$(val1 + "," + val2).mouseleave(function() {

    //Test condition
    if (isHoverSpecialDiv == false) 
    {
        $('.opacity').remove();
        $(val3).show();
        $(val4).hide();
    }
});

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.