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

前端 未结 24 2462
不思量自难忘°
不思量自难忘° 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:07

    WARNING: is(':hover') is deprecated in jquery 1.8+. See this post for a solution.

    You can also use this answer : https://stackoverflow.com/a/6035278/8843 to test if the mouse is hover an element :

    $('#test').click(function() {
        if ($('#hello').is(':hover')) {
            alert('hello');
        }
    });
    

提交回复
热议问题