How do I create an if () mouse is over an element in Jquery?

jquery, mouseover

Solution

At a very high level, what you want is something to:

- Hold a Boolean value.

- When the mouse triggers a MouseOver event, set the Boolean to true.

- When the mouse triggers a MouseOut event, set the Boolean to false.

All you have to do is return the Boolean value to get the `hasMouseOver` value.

Problem

I have some hover() JS code: ``` $( '.leftMenuProductWrapper').hover ( function () { }, function () { }); ``` In the second function, I need something like: ``` If ($("#leftMenuWrapper2").hasMouseover){ do this }else{ do that}; ``` I can't find any documentation on how to do it. EDIT: This appears to be a solution: ``` $('#leftMenuWrapper2').mouseenter(function(){ mouseover = true; }).mouseleave(function(){ mouseover = false; }); ``` And then later on in the code, reference it: ``` if(mouseover == false){ doSomething }; ```

Original source