When the button is clicked you have to find the next item to show. A better construct is the nested list approach where you can find the nested dropdown automatically from the clicked item just by adding a class to the clicked item.
This is the usual html for a dropdown.
<ul class="top-nav">
<li><a href="#">Menu 1</a>
<ul class="sub-nav">
<li><a href="#">sub nav 1</a></li>
<li><a href="#">sub nav 2</a></li>
<li><a href="#">sub nav 3</a></li>
<li><a href="#">sub nav 4</a></li>
</ul>
</li>
<li><a href="#">Menu 2</a>
<ul class="sub-nav">
<li><a href="#">sub nav 1</a></li>
<li><a href="#">sub nav 2</a></li>
<li><a href="#">sub nav 3</a></li>
<li><a href="#">sub nav 4</a></li>
</ul>
</li>
</ul>
You could just change the display:inline-block to display:flex and then buttons would line up horizontally.
Here’s an example with the extra items added and the extra structure required. This is still based on your example.
Things still to consider:
Remove inline event handler and use an event listener in the js instead.
Consider whether this html structure is extensible enough. For instance this structure does not cater for multiple dropdowns unlike the nested list approach. However if you aren’t going in that direction then the html is not too bad although I have a dislike of bare anchors next to each other as that used to be a problem for assistive technologies but I believe they are ok with it now.
Once you’ve settled on an approach I will move to the JS forum for tidying up
Here’s an example with inline event handler removed.
Another consideration to mention is to avoid hiding the menu with display:none as that is not user user friendly (assistive devices and search engines may not read or follow hidden links) but apart from that its not possible to apply animation effects to elements with display:none. usually I hide the menus by absolutely positioning them offscreen to the left and then just bring them back when needed. This allows animations to work.