Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery removeClass except on current id

[ Live Demo ]

I have a navigation menu that displays a certain state when hovered and also displays text in a different div.

In the event that the user does not interact with the menu, the divs auto cycle on their own and the navigation menu displays the corresponding hover state as if the user were interacting.

However, as it is cycling, if the user hovers over another link on the navigation menu, I need to removeClass on the previously highlighted element.

How do I write, "if id is not currently hovered id, then removeClass('hoverBold') on all other navigation links"

like image 286
brianrhea Avatar asked Nov 27 '25 20:11

brianrhea


2 Answers

Look at jQuery not().

Something like...

$('.myMenu').hover(function() {
    $('.myMenu').not(this).removeClass('hoverBold');
});
like image 143
fearofawhackplanet Avatar answered Nov 30 '25 08:11

fearofawhackplanet


Just add this to hoverIn:

links.removeClass('hoverBold');

You don't need to take the class off the other elements, because the current element, a:hover.sliderLinks, shares styling with hoverBold

Working example: http://www.jsfiddle.net/MXSkj/1/

like image 36
Kyle Wild Avatar answered Nov 30 '25 09:11

Kyle Wild



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!