How to create an if () mouse over an element in jQuery?

I have jover () JS code:

$( '.leftMenuProductWrapper').hover (
            function () {



            },
            function () {


    });

In the second function, I need something like:

If ($("#leftMenuWrapper2").hasMouseover){
do this
}else{
do that};

I can not find documentation on how to do this.

EDIT:

It looks like a solution:

$('#leftMenuWrapper2').mouseenter(function(){
    mouseover = true;
}).mouseleave(function(){
    mouseover = false;
});

And then in the code, reference it:

if(mouseover == false){
                doSomething
                };
+3
source share
2 answers

At a very high level, you need something:

  • Hold a boolean value.
  • When the mouse fires the MouseOver event, set Boolean to true.
  • When the mouse fires the MouseOut event, set Boolean to false.

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

+12
source

, , , .

, .leftMenuProductWrapper, - #leftMenuWrapper2... , , , - <div> ( , , "" ). - :

$('.leftMenuProductWrapper>div').hover(function(ev) {
    if ($(this).id == 'leftMenuWrapper2') {
        // do something with this one
    } else {
        // otherwise, do something else
    }
});
0

Source: https://habr.com/ru/post/1737389/


All Articles