I am making a hamburger menu which should display the a tags once it's clicked and hide them again, once it's clicked again. Currently for some reason the a's show when you click twice on the hamburger menu, why and how can I make them display the first time the menu is clicked and hide them again, when the menu get's clicked again?
Here is the html:
<div class="a-container">
<a href="/index.html">Home</a>
<a href="/pages/about.html">About</a>
<a href="/pages/solutions.html">Solutions</a>
<a href="/pages/team.html">Team</a>
<a href="/pages/contact.html">Contact</a>
</div>
the javascript:
let hamburger = document.querySelector('.hamburger');
let menu = document.querySelector('.a-container');
let bod = document.querySelector('.container');
let navLinks = document.querySelector('.a-container');
hamburger.addEventListener('click', function () {
var x = document.querySelector(".a-container");
if (x.style.display === "none") {
x.style.display = "flex";
} else {
x.style.display = "none";
}
hamburger.classList.toggle('isactive');
menu.classList.toggle('active');
});
and the css:
.hamburger {
margin: 0;
margin-left: 15px;
padding: 0;
float: left;
transition: opacity .3s;
}
.hamburger:hover {
cursor: pointer;
opacity: .5;
}
.hamburger .line{
width: 50px;
height: 5px;
background: #01568a;
margin: 8px auto;
transition: all 0.3s ease-in-out;
border-radius: 5px;
}
.hamburger.isactive .line:nth-child(2) {
opacity: 0;
}
.hamburger.isactive .line:nth-child(1) {
transform: translateY(13px) rotate(45deg);
}
.hamburger.isactive .line:nth-child(3) {
transform: translateY(-13px) rotate(-45deg);
}
.a-container {
display: none;
}
.a-contaier.active {
display: block;
animation: fade .5s;
}