I have a ul with the id of "menu-list". The display property is set to "none" in my CSS file, but I want it to switch to "flex" when a link is clicked.
I am trying to use the click event on the link to change the display property, however, nothing happens when I click on it.
When I log the value of the display property to the console inside myFunction(), no value is displayed, just a blank log. What could be the issue?
let menuList = document.getElementById("menu-list");
function myFunction() {
console.log(menuList.style.display);
if (menuList.style.display === "none") {
menuList.style.display = "flex";
} else {
menuList.style.display = "none";
}
}
#menu-list {
display: none;
}
<div class="container">
<div class="inner">
<nav id='menu'>
<div class="logo">
<img src="src/assets/images/hp-logos_white.png" alt="logo" class="fluid">
</div>
<ul id="menu-list">
<li class="menu-list-item"><a href="">Home</a></li>
<li class="menu-list-item"><a href="">Home</a></li>
<li class="menu-list-item"><a href="">Home</a></li>
</ul>
<a href="" class="icon" onclick="myFunction()">
<i class="fa fa-bars"></i>
</a>
</nav>
</div>
</div>