I made a hamburger menu using HTML, CSS, and JS and it works perfectly fine but I want to minimize my JS logic.
I did some research on YouTube, but everyone has almost the same logic.
Look at my JS logic, can I minimize my JS logic?
If you have better short and simple JS logic then answer me.
HTML :
<div class="menu-btn">
<div class="hamburger"></div>
</div>
<div class="menu-list">
<ul class="menu-items">
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#skills">Skills</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
JS logic :
const hamburgerMenu = document.querySelector(".menu-btn");
const hamburger = document.querySelector(".hamburger");
const menuList = document.querySelector(".menu-list");
const homePage = document.getElementById("#home");
hamburgerMenu.onclick = () => {
hamburger.classList.toggle("active");
menuList.classList.toggle("active");
hamburgerMenu.classList.toggle("active");
};
menuList.onclick = function (e) {
if (e.target.classList !== "menu-btn") {
hamburger.classList.remove("active");
menuList.classList.remove("active");
hamburgerMenu.classList.remove("active");
}
};