When I initially click on the selected ID my code does not work on the initial click but then works as expected when I click again. I can see no obvious reason as to why this is happening.
Any help/suggestions would be great.
*I have now added the CSS for further review. Please can you look through the code again as I am having a headache trying to figure this out.
<section>
<div id="top-bar-container">
<img src="img/MSO-logo.jpg" alt="MSO Digital Agency" />
<i id="hamburger-icon" class="fas fa-bars fa-2x"></i>
<nav id="nav-bar">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li>
<a href="#">Services</a>
<ul>
<li><a href="#">Web Design</a></li>
<li><a href="#">Branding</a></li>
<li><a href="#">Consulting</a></li>
<li><a href="#">SEO</a></li>
</ul>
</li>
<li><a href="#">Our Work</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</nav>
</div>
</section>
var hamIcon = document.getElementById("hamburger-icon");
// open and close the navigation menu
hamIcon.onclick = function() {
var navBar = document.getElementById("nav-bar");
if (navBar.style.display === "none") {
navBar.style.display = "block";
} else {
navBar.style.display = "none";
}
};
body {
padding: 0px;
margin: 0px;
font-family: "Roboto", sans-serif;
}
#top-bar-container {
background-color: #ec671c;
width: 100%;
height: 75px;
position: absolute;
z-index: 1;
}
#nav-bar {
width: 75%;
float: right;
padding-right: 50px;
}
#hamburger-icon {
display: none;
color: white;
position: absolute;
right: 20px;
top: 20px;
}
#hamburger-icon:hover {
color: orange;
}
/* START OF MEDIA QUERIES */
@media screen and (max-width: 767px) {
#hamburger-icon {
display: block;
}
#nav-bar {
padding-right: 0px;
margin-top: 50px;
display: none;
}
}