JAVASCRIPT NAVIGATION HELP - /wsr/ (#1531257) [Archived: 725 hours ago]

Anonymous
6/24/2025, 5:46:39 PM No.1531257
Screenshot 2025-06-25 014153
Screenshot 2025-06-25 014153
md5: b056c8a6258e90e0791817f2805cbec5🔍
Help with my javascript navigation for clickable dropdowns in a nav.
> There are multiple dropdown divs in this nav.
> Clickable compared to displayed css for mobile friendly use.

Can't seem to find a way to get this to work
SOURCE
6/24/2025, 5:52:28 PM No.1531258
<nav>
<div class="dropdown">
<button class="dropmain">DROPDOWN <i class="fa fa-caret-down"></i> </button>
<div class="dropdown-links">
<a href="/link1">Link One</a>
<a href="/link2">Link Two</a>
<a href="/link3">Link Three</a>
</div> <!-- .dropdown-links -->
</div> <!-- SERVICES .dropdown -->
</nav>

<script>
document.querySelectorAll("nav .dropdown .dropmain").addEventListener("click", function() {
var innerDiv = document.querySelectorAll("nav .dropdown:hover .dropdown-links");
if (innerDiv.style.display === "none") { innerDiv.style.display = "block";
}
});
</script>
Anonymous
6/25/2025, 7:00:06 AM No.1531328
.dropdown-links is a child of .dropdown, if you click on the links it'll propagate back up and cause it to toggle

Add the listener to .dropmain only or use the children selector ("nav > .dropdown > .dropmain")