Situation: I have created a nav with a click function that allows the sub nav to .slideToggle(); when user clicks the nav link.
Issue: The active class is added to the nav link when clicked but does not remove itself when the user clicks on a sibling nav link. It continues to add active classes one by one.
Questions: How can I properly write the function to add the class to the clicked link, then remove the class when a sibling link is clicked while adding the class to the now selected link, etc...
JS Code:
// Pillar side navigation function
$('.side-nav-link').click(function(e) {
var $pillarNav = $('.pillar-subnav')
$(this).removeClass('side-nav-active');
if ($pillarNav.is(':visible')) {
$pillarNav.slideUp();
$(this).next('ul').stop().slideToggle();
} else {
$(this).next('ul').stop().slideToggle();
}
$(this).addClass('side-nav-active');
e.preventDefault()
});
Here is the working JS Fiddle