Featured Plugin - HYPERCHILD

Beautiful Design, create Child Themes in a single click!

Latest Posts

Divi Hype - Visual Builder Dropdown Navigation Menu - Blog Cover

How to create an Awesome Divi Builder dropdown Navigation Menu

Speed up your website development workflow with our amazing Divi Builder dropdown navigation menu!

DiviHype - How to install Facebook Messenger Chat on your Divi Website

How to add Facebook Messenger Chat to your Divi Website

Introduction It's well known that having a direct method for your website visitors to...
Divi Hype - mobile-parallax

How to add mobile Parallax to your Divi website

IntroductionIf you've landed here, you are probably using Divi to design websites and...
Divi Hype - How to Redirect Divi Filtered Portfolio Items to Custome URLs

How to Redirect Divi Filterable Portfolio items to custom URLs

** UPDATE 25/07/2019 ** I had several requests to update this code so it worked with later...
Divi Hype - How to Create a Divi Child Theme

How to Create a Divi Child Theme

Creating a child theme for Divi or Wordpress is essential if you want to make your own...
Divi Hype - How to create a cool Typewriter Effect in Divi

How to Create a Cool Typewriter Effect in Divi

A recent question was posted up on the Divi Web Designers Facebook group asking how to...
Divi Hype - How to Reveal Divi Content on clicking a Button

How to Reveal Divi Content on Clicking a Button

I recently saw a request on the Divi Web Designers Facebook group asking how to reveal...
Divi Hype - How to create a slide-in mobile menu for Divi

How to create a slide-in Mobile Menu for Divi

Most Divi designers will tell you the one thing that usually gives away a Divi site is the menu....
Divi Hype-How to add an email link to the Divi Person Module

How to add an email link to the Divi Person Module

People often ask how you can add an email link to the Divi Person module. It seems an obvious...

I recently saw a request on the Divi Web Designers Facebook group asking how to reveal Divi content when you click a button. This article from DivNotes works great if you only want one button and one have one section, row or module you want to reveal on the page.

But what do you do if you want more than one button/section on your page, with each button revealing different content? Also, how can you hide content revealed by other buttons each time you click one, giving a toggle effect?

In this tutorial, I’ll give you a bit of jQuery magic that lets you:
1) Create a button that reveals/hides specific content when clicked
2) Hide any content revealed by other buttons clicked previously

First, let’s take a look at the final result…

The final effect

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sed turpis et elit hendrerit malesuada tempus quis sapien. Integer id volutpat magna.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sed turpis et elit hendrerit malesuada tempus quis sapien. Integer id volutpat magna.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sed turpis et elit hendrerit malesuada tempus quis sapien. Integer id volutpat magna.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sed turpis et elit hendrerit malesuada tempus quis sapien. Integer id volutpat magna.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sed turpis et elit hendrerit malesuada tempus quis sapien. Integer id volutpat magna.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sed turpis et elit hendrerit malesuada tempus quis sapien. Integer id volutpat magna.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sed turpis et elit hendrerit malesuada tempus quis sapien. Integer id volutpat magna.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sed turpis et elit hendrerit malesuada tempus quis sapien. Integer id volutpat magna.

How to do it

It’s pretty simple with only a small amount of jQuery and CSS classes applied to the Sections, Rows and button modules. This method enhances to the DiviNotes method. You can create multiple SECTIONS, each with its own button and one or more rows/modules that are revealed when you click the button. In addition, the code closes any other rows/modules opened by other buttons on the page giving the ‘toggle’ effect.

Create a section

Create a section on your page and give it a CSS class of reveal_section. To do this, go to the Divi settings for the section, then in the Advanced tab add ‘reveal_section‘ in the CSS class box like this:

Divi Hype - How to Create Sections in Divi that Toggle open when you click a button - section class settings

Add a Button

Create a new row in your section and add a button to it. Give the button a CSS class of reveal_button. To do this, again go to the settings for your button module and in the Advanced tab add ‘reveal_button‘ in the CSS class box like this:

Divi Hype - How to Create Sections in Divi that Toggle open when you click a button - button class settings

Set up the content to reveal when you click the button

The great thing about this method is that you can set up one or more rows or even individual modules within rows that will all be revealed at the same time when you click the button in the same section, giving much greater flexibility for your design.

Add one or more extra rows to your section, add whatever content you want into these rows and then add the class ‘reveal_content‘ to either the entire row/s or the individual module/s you want to reveal when the button is clicked.

Adding the class to a row:
Divi Hype - How to Create Sections in Divi that Toggle open when you click a button - row class settings

Adding the class to a module:
Divi Hype - How to Create Sections in Divi that Toggle open when you click a button - module class settings

Repeat as necessary!

You can repeat the process as many times as you like on your page. Create more sections with class ‘reveal_section‘, add a row with a button to each section and give the button the class ‘reveal_button‘. Then add extra content to the section, giving each row or module you want to reveal the class ‘reveal_content‘.

Add the jQuery Code

And below is the jQuery script that does the magic. To load it, you can either:
1) Add it to a Divi code module on the same page as your sections. Make sure to wrap it in a <script></script> tag
2) In your Admin area, go to Divi > Theme Options > Integration and paste it into the box labelled “Add code to the < head > of your blog”. Again, make sure to wrap the code in a <script></script> tag
3) If you’re using a child theme, add the code to a new JS file and enqueue it in your child theme functions.php file

jQuery(document).ready(function($) {

  //Hide all content to be revealed
  $('.reveal_content').hide();

  //Create the click event for each reveal button
  $('.reveal_button').click(function (e) {

  //Prevent the default button action (i.e. redirecting to a url)
    e.preventDefault();

    //Get the parent section for the button clicked
  $parent_section = $(this).closest('.reveal_section');

  //Remove the opened class from all other buttons
  $('.reveal_button').not(this).removeClass('opened');

  //Close all content in other sections
  $('.reveal_section').not($parent_section).find('.reveal_content').fadeOut('slow');

  //Hide/Reveal the content in the same section as the button clicked
  $(this).addClass('opened');
  $parent_section.find('.reveal_content').each(function() {
    $(this).slideToggle();
  }
  )

  });

  }
)

 

Add CSS Styling for the button

Similar to the DiviNotes method, let’s add some CSS to switch the button icon to indicate whether it’s opened or closed. We’ll also force the button icon to display regardless of your default Divi button settings and pad the button out so the icon is nicely inside the boundary of the button, making it look a lot cleaner. Here’s the CSS for this:

<style>
.et_pb_button.reveal_button, .et_pb_button.reveal_button:hover {
    padding-right: 40px!important;
}

.reveal_button:after {
    display: inline-block!important;
    opacity: 1!important;
    margin-left: 0!important;
    content: '\33';
    transition: all 0.5s ease;
}
.reveal_button.opened:after {
  content: '\32';
}
</style>

 

Rounding up

So there you go. You can now add multiple areas on your page that are opened by different buttons and toggle any other opened areas closed at the same time. Simply add the jQuery script, then create as many sections/buttons/rows/modules on your page as you like with the classes shown below:
Divi Hype - How to Create Sections in Divi that Toggle open when you click a button - class settings

Each button only reveals/hides content within the same section that has a class of ‘reveal_content’. Pretty awesome huh?

If you found this useful, leave us a comment!

Download the layout

After a few requests for this, I’ve bundled the demo sections above and the jQuery code (in a code module) into a downloadable layout. Click HERE to download it.

About the Author

Divi Hype - Ed Solman Avatar Large

Ed Solman

Entrepreneur, Blogger and Website Developer/Designer. Passionate about helping people and businesses develop and grow. Daredevil sportsbike enthusiast.

Divi Hype favicon light

Get the Hype

Join our mailing listĀ for allĀ the latest Hype and get our massive Freebie bundle,Ā with all our Custom module layouts andĀ theĀ HyperChild pluginĀ for FREE!

You have Successfully Subscribed!