When I click the hamburger menu button I want both .menu-btn
.menu-mob
the menu button and the navigation menu the have to is-active
class and .sqr
to have the class .hidden
when the other two are active. That's why I used toggle() to toggle all these classes, but for some reason it is not working.
Note that I'm using react and tailwind and some vanilla css
const showNav = () => {
const menuBtn = document.querySelector('.menu-btn')
const navbar = document.querySelector('.menumob')
const sqr = document.querySelector('.sqr')
menuBtn.addEventListener('click', () => {
menuBtn.classList.toggle('is-active')
navbar.classList.toggle('is-active')
sqr.classList.toggle('hidden')
})
<button class="menu-btn hamburger absolute top-0 right-0 md:hidden" onClick={showNav()}>
<div class="bar"></div>
</button>
.hamburger.is-active::before {
transform: rotate(-45deg) translate(-8px, 6px);
}
.hamburger.is-active::after {
transform: rotate(45deg) translate(-9px, -8px);
}
.hamburger.is-active .bar {
opacity: 0;
}
.menumob {
position: relative;
top:0;
left:100%;
transition: 0.4s;
}
.menumob.is-active {
left:0;
}