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

$('.xx').mouseenter(function(){
  if($(this).is(':hover'))
    alert('d');
  else
     alert('f');
});

Here is my code, it should alert 'd' but every time it alerts 'f' What's error Here


Solution 1:

function idIsHovered(id){
    return $("#" + id + ":hover").length > 0;
}

http://jsfiddle.net/mathheadinclouds/V342R/

Solution 2:

:hover is a CSS pseudo-class, not a jQuery selector. It cannot be reliably used with is() on all browsers.

Solution 3:

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.

Solution 4:

Try something like this-

$('.xx').hover(function(){        
        alert('d');
    }, function() {
       alert('f);
    });