Jquery condition check is(':hover') not working

后端 未结 8 1341
-上瘾入骨i
-上瘾入骨i 2020-11-28 15:15
$(\'.xx\').mouseenter(function(){
  if($(this).is(\':hover\'))
    alert(\'d\');
  else
     alert(\'f\');
});

Here is my code, it should alert \'d

8条回答
  •  执笔经年
    2020-11-28 15:43

    As Frederic said, :hover is part of CSS and is not a selector in jQuery.

    For an alternative solution, read How do I check if the mouse is over an element in jQuery?

    Set a timeout on the mouseout to fadeout and store the return value to data in the object. Then onmouseover, cancel the timeout if there is a value in the data.

    Remove the data on callback of the fadeout.

提交回复
热议问题