Can someone help me create a dropdown menu using a JavaScript function that toggles on click? I've attempted to do so with the following code, but it's not working as expected. Could you please point out where I might be going wrong? I'm looking to implement this purely in JavaScript and I am utilizing SASS for styling purposes.
Below is the code snippet:
let home = document.getElementById('home');
let underhome = document.querySelector('under-home');
home.addEventListener('click', function() {
underhome.classList.toggle('open');
});
.navbar .slider .hammburger-links {
padding: 0 1.250em;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.navbar .slider .hammburger-links a {
padding: 0 1.500em;
text-decoration: none;
font-family: "Helvetica", Arial;
font-size: 11px;
color: #a6adb4;
}
.navbar .slider .hammburger-links .under-home {
position: absolute;
top: 5%;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
background: #F6F8F9;
min-width: 12.5em;
min-height: 12.5em;
z-index: 1;
display: none;
}
.navbar .slider .hammburger-links .under-home a {
margin: 10px 0;
}
.navbar .slider .hammburger-links .open {
display: inline;
<div class="navbar">
<div class="slider">
<div class="hammburger-links">
<a href="" id="home">HOME</a>
<div class="under-home">
<a href="">WORLD NEWS</a>
<a href="">TRAVEL</a>
<a href="">TECHNOLOGY</a>
<a href="">CITY</a>
<a href="">CULTURE</a>
<a href="">MORE...</a>
</div>
<a href="">DISCOVERY</a>
<a href="">PHOTOS</a>
<a href="">CONTACT</a>
<img src="images/navbar-img.png" alt="">
</div>
</div>
</div>