I am trying to update the active state of a navigation tab. When the tab is clicked (newActive) is suppose to gain the class .active
and the previous active tab (oldActive) needs to loose it.
So far I am able to remove the active class from oldActive, I also tried aadding a class to it and worked fine, but I am not able to do any changes to newActive when I defined it as $(this)
nor when I define it as event.currentTarget
.
I am also not getting any errors in the console so I can't get a lead on what's going on.
JQuery code:
$('.navigation_tabs li').click( event => {
let oldActive = $('.navigation_tabs li.active');
let newActive = event.currentTarget;
oldActive.removeClass("active");
// this line is not working nor giving any errors
newActive.addClass("active");
loadContent(data[newActive.dataset.list]);
});
HTML nav markup:
<div class="navigation">
<ul class="navigation_tabs">
<li class="active" data-list="build">Build</li>
<li data-list="plan">Plan</li>
<li data-list="innovate">Innovate</li>
<li data-list="interact">Interact</li>
<li data-list="scale">Scale</li>
<li data-list="service">Service</li>
<li data-list="enhance">Enhance</li>
<li data-list="general">General</li>
</ul>
</div>