Reputation: 2577
I want to check if a element is being hovered over. I get this error:
Syntax error, unrecognized expression: unsupported pseudo: hover
when I use this code:
$('.class').blur(function(){
if(!$(this).is(':hover')){
//element not being hovered over
}
});
i also tried this:
$('.class').blur(function(){
if($(this+":hover").length === 0){
//element not being hovered over
}
});
this also does not work. Is there any other way of doing this. Thanks.
Upvotes: 6
Views: 1408
Reputation: 2717
jQuery has this functionality built-in. See documentation on .hover()
$(".class").hover(
function() {
// item is being hovered over
$(this).addClass('hover');
}, function() {
// item is no longer being hovered over
$(this).removeClass('hover');
}
);
Upvotes: 0
Reputation: 554
$(".class").mouseover(function(){
$(this).attr('checked',true);
});
});
Upvotes: 1