How do I check if the mouse is over an element in jQuery?

前端 未结 24 2449
不思量自难忘°
不思量自难忘° 2020-11-22 08:10

Is there a quick & easy way to do this in jQuery that I\'m missing?

I don\'t want to use the mouseover event because I\'m already using it for something else. I

24条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 09:09

    I have answered this in another question, with all details you may need:

    Detect IF hovering over element with jQuery (has 99 upvotes at the time of writing)

    Basically, you can do something like:

    var ishovered = oi.is(":hover");
    

    This works only if oi is a jQuery object containing a single element. If there are multiple elements matched, you need to apply to each element, for example:

    var hoveredItem = !!$('ol>li').filter(function() { return $(this).is(":hover"); });
                      // not .filter(':hover'), as we can't apply :hover on multiple elements
    

    This was tested starting jQuery 1.7.

提交回复
热议问题