开发者

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

开发者 https://www.devze.com 2022-12-23 10:45 出处:网络
I have some hover() JS code: $( \'.leftMenuProductWrapper\').hover ( function () { }, function () { }); In the second function, I need something li开发者_运维知识库ke:

I have some hover() JS code:

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



            },
            function () {


    });

In the second function, I need something li开发者_运维知识库ke:

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
                };


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.


I'm not entirely sure what you're doing but it looks like you're attacking this from the wrong angle.

I'm assuming you've got multiple elements inside .leftMenuProductWrapper, one of which is #leftMenuWrapper2... I assume the elements you care about are <div>s (but you can edit the code to fit if they're not). Try something like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号