Toggle Show-Hide JQuery

In this section we go over how to toggle a section or row with a click of a button. For example if we have a page of reviews but we only want to show some of those reviews, we can hide them and have more populate with a button click. Paste the below code in a code block Divi module.

<script type=”text/javascript”>
jQuery(document).ready(function() {
// Hide the div
jQuery(‘#show-reviews’).hide();
jQuery(‘.toggle-button’).click(function(e){
e.preventDefault();jQuery(“#show-reviews”).slideToggle();
jQuery(‘.toggle-button’).toggleClass(‘opened closed’);
});
});
</script>

***Make sure to give the button module the class of “toggle-button and the row or section you want to hide an ID of show-reviews” for this to work correctly. You can rename the class and ID to whatever you’d like but in this example those are the values given.

Test Your Knowledge

To Do: Toggle Show-Hide JQuery

Complete this test your knowledge section on the “Testimonials” page. Watch the above video and do your best to recreate the website shown in the below gif.

Completed Website

As you work through the Divi training, you’ll build out the below website. Each training will add to the website. Build out the website on the pizzazzgrouptyk.com domain from the inmotion 101 training.