Webflow sync, pageviews & more.
NEW

How can I close a dropdown in Webflow when clicking on a link?

TL;DR
  • Add a click interaction to the link inside the dropdown that triggers a "Start an Animation" targeting the dropdown toggle.
  • If interactions aren’t sufficient, use a custom JavaScript snippet to simulate a click on the dropdown toggle when the link is clicked.
  • Assign a unique class (e.g., dropdown-close-link) to the link and test the behavior after publishing.

The issue involves ensuring that when a user clicks a link inside a Webflow dropdown, the dropdown automatically closes.

1. Use Custom Code to Close the Dropdown

Add a custom code snippet in your Webflow project settings (Site Settings > Custom Code > Before tag) or embed it on the page.
Write JavaScript that listens for clicks on links within the dropdown, then finds the relevant dropdown element and removes its “w--open” class to close it.
Example logic: For each link inside a dropdown (e.g., selectors like .w-dropdown-list a), attach a click event. When clicked, locate the closest parent with class “w-dropdown” and remove the “w--open” class from it.

2. Utilize Webflow Interactions (Optional)

Set up an interaction on your link element: add an additional click animation that targets the dropdown’s toggle or list.
Simulate a click on the dropdown button that normally toggles the state. This can close the dropdown by re-triggering its built-in behavior.
Ensure consistency by testing that the click both navigates if needed and closes the dropdown properly.

3. Test and Publish

Preview your site in Webflow Designer and test clicking the dropdown link to confirm that the dropdown closes.
Publish the changes so that the custom code or interactions take effect on the live site.
Double-check mobile and desktop behavior to ensure the solution works across devices.

Summary

By either adding a custom JavaScript snippet to remove the “w--open” class on click or creating an interaction that simulates a click on the dropdown toggle, you can close a Webflow dropdown when a link is clicked.

Rate this answer

Other Webflow Questions