CSS in Divi - Trigger an accordion/toggle to open when clicking on a blurb

I have been using the below to trigger accordion/toggle modules to open when a button is selected, but it ONLY works when the trigger is a button module:

jQuery(function ($) {
//open toggle on button click
$('.urbanplanning-appreq-button').on('click', function(event){
    $('#urbanplanning-appreq.et_pb_toggle_1 .et_pb_toggle_title').click();
});
});

in which .urbanplanning-appreq-button is the class of the button and #urbanplanning-appreq is the id of the toggle it scrolls to and opens. I can't figure out how to get a solution for when the trigger is a blurb module and not a button. This is what I've written but it is not working:

<script>
jQuery(function ($) {
$('#open-urbanplanningcurriculum .et_pb_blurb_0.et_pb_blurb').on('click', function(event){
$('#urbanplanningcurriculum .et_pb_toggle_1 .et_pb_toggle_title').click();
});
});
</script>

in which #open-urbanplanningcurriculum is the id of the blurb module (first in the list hence the '0') and #urbanplanningcurriculum is the id of the toggle it should open (second in the list hence the '1'). Any tips for what I'm doing wrong?

1 answer

  • answered 2021-07-21 15:46 lukasemory

    I found the solution. Instead of triggering a click, I needed to remove the class that keeps the toggle closed and add the class that opens the toggle:

    <script>
    jQuery(function ($) {
    $('#open-urbanplanningcurriculum a').on('click', function(event){
    $('#urbanplanningcurriculum').removeClass('et_pb_toggle_close').addClass('et_pb_toggle_open'); return false;
    });
    });
    </script>
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum