I am trying to add class for <li>
elements on click event. If I click on the first element it should to get class "current-tab" and others <li>
elements should not contain that class and etc.
Here is some HTML code:
<nav class="interest-nav">
<ul id="interest-ul">
<li><a href="#box1">Fashion</a></li>
<li><a href="#box2">Movies</a></li>
<li><a href="#box3">TV</a></li>
</ul>
</nav>
and Javascript code:
var navUl = document.getElementById('interest-ul').getElementsByTagName('li');
for (var y = 0; y < navUl.length; y++) {
navUl[y].addEventListener('click', checkLi);
}
function checkLi() {
if (navUl.className === '') {
navUl.className = 'current-tab';
} else {
navUl.className = '';
}
}
Thank you for your attention and for your help!