Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 306
Wasim A. Avatar asked Nov 04 '11 13:11

Wasim A.


3 Answers

x.filter(':hover').length

This may be also usable when you already had queried some objects / or inside callback function.

like image 79
l00k Avatar answered Sep 26 '22 21:09

l00k


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

like image 20
Frédéric Hamidi Avatar answered Sep 23 '22 21:09

Frédéric Hamidi


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

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

like image 34
mathheadinclouds Avatar answered Sep 22 '22 21:09

mathheadinclouds