Is there a way to decouple the triggers in a Webflow accordion so that opening one dropdown does not close all others?

Published on
September 22, 2023

Yes, there is a way to decouple the triggers in a Webflow accordion so that opening one dropdown does not close all others. By default, Webflow's built-in accordion component closes other dropdowns when one is opened. However, you can achieve the desired behavior by using custom code and interactions.

Here's a step-by-step guide on how to decouple the triggers in a Webflow accordion:

  1. Create an accordion element: Add a parent element to the page and give it a class name to target it with custom code.

  2. Add individual dropdowns: Inside the parent element, add individual dropdown elements. Each dropdown should have a trigger element and a content element.

  3. Give each trigger element a unique class name: Select each trigger element within the dropdown and assign them unique class names. This will allow you to target them individually with custom code.

  4. Write custom code: Open the Page Settings panel and go to the Custom Code tab. In the Footer Code section, paste the following code snippet:

<script>document.addEventListener('DOMContentLoaded', function() {    const triggers = document.querySelectorAll('.accordion-trigger');    const contents = document.querySelectorAll('.accordion-content');    triggers.forEach((trigger) => {        trigger.addEventListener('click', function() {            const content = this.nextElementSibling;            if (content.style.maxHeight) {                content.style.maxHeight = null;            } else {                // Close other open dropdowns                contents.forEach((c) => {                    if (c !== content && c.style.maxHeight) {                        c.style.maxHeight = null;                    }                });                content.style.maxHeight = content.scrollHeight + 'px';            }        });    });});</script>

This code adds an event listener to each trigger element and toggles the max-height of the corresponding content element. It also closes any other open dropdowns before opening the selected one.

  1. Publish and test: Save your changes and publish the site. Test the accordion functionality by opening one dropdown and ensuring that it doesn't close the others.

By following these steps, you can easily decouple the triggers in a Webflow accordion and have more control over the behavior of your dropdowns.

Additional questions that users may use to search for this answer:

  1. How can I prevent Webflow accordion from closing other dropdowns?
  2. Webflow: How to stop accordion from closing other dropdowns?
  3. Is there a way to customize the behavior of Webflow accordion?