There is a menu with two tabs that contain submenus. When clicking on a tab, two events should occur:
1) when clicking on an element, the .active
class is added to this element, and the .active
class should be removed for another element.
2) the active tab of the menu is visible. The second menu is hidden, has a class .hide
. And accordingly, when you click on the corresponding tab, the menu becomes visible.
How to delete a class .active
at an element when adding a class .active
another element? And how to link the active tabs with the display of the hidden menu, i.e. remove class .hide
?
document.addEventListener('DOMContentLoaded', function () { var wrapnavs = document.getElementById('js-navigation'), navs = wrapnavs.getElementsByTagName('div'); for( var i = 0; i < navs.length; i++ ){ navs[i].addEventListener('click', selectMenu); } function selectMenu() { if(this.classList.contains('active')){ this.classList.remove('active'); } else { this.classList.add('active'); } } console.log('get to the choppa!!!'); });