How To Set The Divi Accordion Module Default State Open Or Closed

by | Apr 4, 2024 | Tips & Tricks, Tutorials | 0 comments

In this guide, we’ll explore how to automatically open or close Divi accordions when a webpage loads. For the Accordion, there’s no default option to control the state of all accordions at once. To address this, we’ll learn how to achieve it using a simple jQuery Snippet. Throughout this tutorial, we’ll demonstrate how to set the default state of Divi Accordion modules to either open or closed with the help of jQuery.

Adjusting the Default State of the Divi Accordion Module

It’s a bit tricky with the Divi accordion module compared to the Toggle module. Right now, there’s no direct option for adjusting this in the Accordion module settings. What makes it a bit frustrating is that the first item in the accordion is automatically open when you load the page. If only tweaking it were as straightforward as it is with the Toggle module!

Read More: How To Add Shape Dividers In Divi

Assign a CSS Class to the Accordion Module

To start customizing the Accordion module, the first thing we need to do is assign it a custom CSS class. This class will help us specifically target this Accordion module later on when we’re using jQuery code. To do this, go to the settings of the Accordion module and find the Advanced tab. Inside this tab, look for the CSS ID & Classes option and toggle it open. Now, you’ll see a field labeled CSS Class. In this field, type in the custom class name dc-accordion. Once you’ve done this, the Accordion module will be ready for further customization using jQuery.

To start customizing the Accordion module, the first thing we need to do is assign it a special class.

Assign a CSS Class to the Accordion Module

Read More: Understanding & Adding Captcha to Your Divi Website: Step-by-Step Guide (2024)

Incorporate the jQuery Code

To make sure your Divi Accordion modules are initially closed on your website, the final step involves adding a small piece of jQuery code. This code will provide the functionality to automatically close the Accordion modules by default. It’s like giving your website a little instruction that says, “Hey, keep these Accordion sections closed when the page loads.” This step ensures a neat and tidy look for your website, with a clean and organized appearance right from the start.

Copy the JQuery Code from here

paste this code in your Divi>Theme Options>Integrations tab in the Add code to the < head > of your blog code area.

This code will provide the functionality to automatically close the Accordion modules by default.

Pasting the JQuery Code to the Divi Dashboard

In the given code, there’s a variable called “setState” that’s initially set to “close” in our example. You have the option to modify this to “open” if you prefer. When “setState” is set to “close,” the code will automatically close all the accordion elements when the page loads. Conversely, if you set it to “open,” the code will open all the accordions as the page loads. Feel free to customize this variable based on your desired initial accordion state.

Read More: Beginner’s Guide to WordPress: Step-by-Step Tutorial (2024)


In conclusion, mastering the default state of Divi Accordion modules can greatly enhance the visual appeal and functionality of your website. Despite the absence of a direct option in the Accordion module settings, we’ve walked through a simple and effective solution using a jQuery snippet.

By assigning a custom class to the Accordion module and incorporating the provided jQuery code, you gain the power to control whether the accordions start off open or closed when visitors land on your webpage. The flexibility to set the initial state as “close” or “open” gives you the freedom to tailor the user experience to match your design preferences.

Don’t forget to seamlessly integrate the jQuery code into your Divi theme by pasting it into the designated area under Divi > Theme Options > Integrations tab. This small addition ensures that your accordions behave just the way you envision, providing a clean and organized appearance from the moment your website loads.

Experiment with different settings, and enjoy the newfound control over your Divi Accordion modules, contributing to a more polished and user-friendly website.

Read More: 9 Top 404 Error Page Layouts for Divi in 2024 


Submit a Comment

Your email address will not be published. Required fields are marked *

Featured Divi Products


Recommended Hosting

Pin It on Pinterest