Skip to content
Advertisement

How to make one dropdown close when clicking another dropdown

I have 2 href links in one page and on click the href opens. But when I click the other href (without closing the first one) the first one stays open.

How can I solve this?

At first I tried to only open and close the dropdown with CSS, but that got really messy because of the two buttons. Now I can open both buttons and close them when I click oudside of the button-area or on the button itself again. But it doesn’t close when clicking the other button.

I imagine this isn’t a hard thing to solve but I just can’t seem to figure it out.

Thanks a lot!

dashboard_home.html

JavaScript

dashboard_home.css

JavaScript

Advertisement

Answer

When you click outside of button area, if its getting closed. then you should keep both links in different div and adjust the style of button class as per your need.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement