Divi “Read More” Button with jQuery

How to Reveal a Hidden Section on Click in Divi?

In this tutorial, I will show you how to reveal a hidden section on click with jQuery. It’s quite easy with bit of code, and I will also show you how to add (or remove) a nice automatic scroll once the hidden section is revealed.

You can watch the video tutorial on YouTube or read the instructions below, or do a combination of both, whatever you prefer. If you’d like to be the first to know whenever I post a new video tutorial, I encourage you to subscribe to my YouTube channel and hit the notification bell to get updates.

Just one quit note here: if you’re just starting out with custom coding or want to brush up your skills, we have a free CSS in Divi Beginner Guide.

All right, let’s get started!

Step 1

Create a button trigger

The example I’m showing you in the video is using a Divi Button module as a trigger. To make it work, add a custom CSS class of dl-read-more to the Button Settings -> Advanced tab.

Make sure that the Button Link URL in the Content tab is an anchor link and uses the ID of the hidden section with the hashtag symbol. In our example it’s #more.

Step 2

Create a section to hide

Add a new section which will be hidden initially. Make sure to set the correct CSS ID in the Advanced tab. It needs to match the Button URL from Step 1. In our example the ID is more (without the hash symbol).

Step 3

Use CSS to hide the section

We are targeting the section with CSS to hide it, but only on the front-end. The section will remain visible in the Visual Builder, so that you can easily edit it if needed.

body:not(.et-fb) #more {
    display:none;
}
Step 4

Use jQuery to show the section on button click

The jQuery script can be placed inside a Code module directly on your page, or (if it’s a functionality you’d like to use globally in various places on your website) inside the Theme Options Integration tab. When the Button with dl-read-more CSS class is clicked, it will slide down the section with ID more and it will hide the button itself (since we are not doing read more/read less – the button is no longer needed).

<script>
jQuery(document).ready(function($) {
	$('.dl-read-more').click(function(){
		$('#more').slideDown();
		$(this).hide();
	});
});
</script>
Optional

Modify the code to prevent the page scroll

The jQuery script can be placed inside a Code module directly on your page, or (if it’s a functionality you’d like to use globally in various places on your website) inside the Theme Options Integration tab. When the Button with dl-read-more CSS class is clicked, it will slide down the section with ID more and it will hide the button itself (since we are not doing read more/read less – the button is no longer needed).

<script>
jQuery(document).ready(function($) {
	$('.dl-read-more').click(function(e){
		e.preventDefault();
		$('#more').slideDown();
		$(this).hide();
	});
});
</script>

How to use this method for multiple sections?

The example I showed you in the video walkthrough using the code above will only work in one place – with one button and one section. Follow the steps below and modify the code so that it can be used for multiple sections on one page.

1. Each button URL and section ID needs to have corresponding name (just like we used “more” in our single-section example).

2. Every button will still use the custom CSS class of dl-read-more and every hidden section could also use a CSS class, eg. dl-hidden-section. This way, you’ll be able to target (and hide!) every section at once with this modified CSS code:

body:not(.et-fb) .dl-hidden-section {
    display:none;
}
3. Use this modified jQuery code to make sure it works for every button & section pair:

<script>
jQuery(document).ready(function($) {
	$('.dl-read-more').click(function(){
		target = $(this).attr('href');
		$(target).slideDown();
		$(this).hide();
	});
});
</script>

Or this code below, if you’d like to prevent the page scroll:

<script>
jQuery(document).ready(function($) {
	$('.dl-read-more').unbind().click(function(e){
		e.preventDefault();
		target = $(this).attr('href');
		$(target).slideDown();
		$(this).hide();
	});
});
</script>

And that’s it!

I hope you enjoyed this tutorial, and I hope everything was clear and accessible. If you happen to use these tips, please let me know in the comments! I always love seeing your feedback, it helps me see if you find my content helpful and if I should make more tutorials like this one.

And if you have any questions, you can ask them in the comments below or in my Divi Lovers Facebook group. It’s a fantastic community of Divi users and web designers where we share useful tips and tricks.

Have you seen our

Divi child themes?

Divi Toolbox plugin?

We offer a great selection of high-quality Divi products to speed up your work. Feel free to use a coupon code IREADBLOG at the checkout to get a 10% discount!

2 Comments

  1. Mark

    This is AWESOME! Can you tell me how hidden content impacts page load and SEO? Specifically, does the content still download even if it isn’t visible? And does Google see the content in the code even if it isn’t visible?

    Thanks so much!

    Reply
  2. Arndt

    Hi and thanks for this tutorial! Is there a way, that the button is still visible to close it?

    Regards
    Arndt

    Reply

Submit a Comment

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

Enjoing our content?

You might find this interesting…

License Details

REGULAR LICENSE

Single Site

A regular license allows an item to be used in one project for either personal or commercial use by you or on behalf of a client. The item cannot be offered for resell either on its own or as a part of a project. Distribution of source files is not permitted.

EXTENDED LICENSE

Unlimited Sites

An extended license allows an item to be used in unlimited projects for either personal or commercial use. The item cannot be offered for resell either on its own or as a part of a project. Distribution of source files is not permitted.

SUPPORT & UPDATES

Each license is a one-time payment. There are no annual fees. You get lifetime access to product updates. Support is provided for 6 months from the date of purchase.

Server Requirements

SERVER SETTINGS:

  • PHP 7.2 or later
  • upload_max_filesize (256M)
  • max_input_time (300)
  • memory_limit (256M)
  • max_execution_time (300)
  • post_max_size (512M)

PHP.INI SETTINGS:

  • php-xml or/and php-dom
  • XMLReader
  • PHP CURL module

PHP MODULES:

  • allow_url_fopen

Would you like to...

Consult Ania and fellow students?

Join the conversation inside our private FB group.

Would you like to...

Get support privately?

Submit a support ticket via your account page.

Ask Ania?

Submit a question for the next live Q&A session.

Consult fellow students?

Join the conversation inside our private FB group.