I have created a profile menu with a dropdown menu using html and css. Now to toggle between closing and opening the dropdown I have added a script file but it is not working. How can I change my script function to achieve the toggle functionality?
let profilemenu = document.getElementById("profileMenu");
function toggleMenu() {
profilemenu.classList.toggle("open-menu");
}
.profile-menu-wrap {
position: absolute;
top: 100%;
right: 24%;
width: 320px;
max-height: 0;
overflow: hidden;
transition: max-height 0.5s;
}
.profile-menu-wrap .open-menu {
max-height: 400px;
}
<div class="navbar-right">
<div class="online">
<img src="https://via.placeholder.com/150?text=toggle-menu" class="nav-profile-img" onclick="toggleMenu()">
</div>
</div>
<!-- ----------------------------profile-dropdown----------------------------------- -->
<div class="profile-menu-wrap" id="profileMenu">
<div class="profile-menu">
<div class="user-info">
<img src="https://via.placeholder.com/50?text=profile">
<div>
<h3>James Sheldon</h3>
<p>Full-stack Developer at Bizwy</p>
<a href="#">View Profile</a>
</div>
</div>
<hr>
<a href="#" class="profile-menu-link">
<img src="https://via.placeholder.com/50?text=feedback">
<p>Give Feedback</p>
<span>></span>
</a>
<a href="#" class="profile-menu-link">
<img src="https://via.placeholder.com/50?text=setting">
<p>Settings & Privacy</p>
<span>></span>
</a>
<a href="#" class="profile-menu-link">
<img src="https://via.placeholder.com/50?text=help">
<p>Help & Support</p>
<span>></span>
</a>
<a href="#" class="profile-menu-link">
<img src="https://via.placeholder.com/50?text=logout">
<p>Logout</p>
<span>></span>
</a>
</div>
</div>
Above is my code, I have given the max-height as 0 to close the dropdown and changed the max-height to 400px with the new class to show the dropdown.
How can I solve the problem I faced with closing and opening the dropdown menu?