I need to add a class to an li
on hover but remove the same class from all other li
s in the list (this is for a nav).
The code I have so far is:
jQuery(".navcontent").on('mouseenter', 'li', function() {
if (jQuery('.childmenu', this)) {
jQuery('.childmenu', this).addClass("child-active");
} else {
jQuery('.navcontent li .childmenu').removeClass("child-active");
}
});
I can't quite work out what I need to do...
Any help would be much appreciated.
You have alternative ways to do that:
jQuery(".navcontent li").on('mouseenter', function() { jQuery('.childmenu').removeClass("child-active"); jQuery('.childmenu', this).addClass("child-active"); });
siblings
:jQuery(".navcontent li").on('mouseenter', function() { jQuery('.childmenu', this).addClass("child-active") .siblings('.childmenu').removeClass("child-active"); });