Reputation: 11
When I try this.
<ul id="sub_navigation"><li>A</li><li>B</li></ul>
with jQuery hover like this
$(function() {
$('#sub_navigation').hover(function() {
$(this).addClass('hovered');
},
function() {
$(this).removeClass('hovered');
});
alert($('#sub_navigation').is('.hovered'));
});
always return false when I hover at sub_navigation.
there is something wrong?
thanks
Upvotes: 0
Views: 1576
Reputation: 630627
Returning false is normal here, since you're alerting when the page loads, instead of when you hover. For example this would return true
:
$(function() {
$('#sub_navigation').hover(function() {
$(this).addClass('hovered');
alert($('#sub_navigation').is('.hovered'));
}, function() {
$(this).removeClass('hovered');
});
});
Keep in mind though, if you're doing this just for styling, using the :hover
CSS pseudo-class will work in all browsers except IE6 here (with no JavaScript):
#sub_navigation:hover { color: red; }
Upvotes: 3