Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
                };
like image 445
Jared Avatar asked Dec 17 '22 02:12

Jared


1 Answers

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.

like image 59
Justin Niessner Avatar answered Dec 30 '22 04:12

Justin Niessner