I currently have a menu that appears when a mobile button is clicked. When a user clicks off the div, I want the div to hide. Right now, I have an 'X' the user must click to hide the div. How can I accomplish what I'm trying to do? (I believe I included all necessary code - but if I missed something, let me know.)
Thank you in advance!
HTML
<div class="nav-mobile">
<a href="#link1">Menu Item 1</a>
<a href="#link2">Menu Item 2</a>
</div>
JS
if (nav-mobile) {
nav-mobile.addEventListener('click', () => {
nav.classList.toggle('active');
});
}
SCSS
(by default is hidden)
.nav-mobile {
visibility: hidden;
}
(when mobile navigation is active, it becomes visible)
&.active {
.nav-mobile {
visibility: visible;
opacity: 1;
h5:not(nav-mobile-title) {
margin: 0;
}
}
}