How To Automatically Open A Toggle Module When Linking To It Tutorial by Pee Aye Creative

How To Automatically Open A Toggle Module When Linking To It

In this tutorial I will show you how to automatically scroll to and open a Divi Toggle module by clicking a link or button.

Join subscribers on our YouTube channel and enjoy other Divi video tutorials!

1. Add A Custom CSS ID To The Toggle Modules

The first thing to do is add a custom CSS ID to the Divi Toggle modules that you want to open. Each toggle ID must be unique. So you could do something like pa_toggle_1 in the first one, pa_toggle_2 in the second one, and so on. Open the module settings and go to the Advanced tab. Go to the CSS IDs & Classes toggle. Place the ID in the CSS ID input field of each Toggle module.

add a custom CSS ID in the toggle module to open on link

2. Add The CSS ID In The Link

Next you need to match the link to the toggle by using the same CSS ID in a button or other link. You just need to add the CSS ID as the anchor link. Clicking this link will just scroll down the page to the Toggle and open it!

If you are using a Button module, open the settings and go to the Link toggle and place the same CSS ID used in the Toggle module into the Button Link URL field.

link to a toggle by adding the custom CSS ID in a button module link field

3. Add A CSS Class To The Buttons

In the same button module, go to the Advanced tab to the CSS ID & Classes toggle and place the class “pa_toggle_buttons” into the CSS Class input field.

add link to buttons that open toggle modules

4. Add The jQuery Snippet To Open The Toggles

The last step is to add the jQuery snippet below to your website. This snippet does the work of opening the toggle modules when you click the button/link. 

If you are using our free Divi child theme, place this snippet into the scripts.js file and remove the <script> tags at the beginning and end. Otherwise, place this in your Divi>Theme Options>Integrations tab in the "Add code to the < head > of your blog" code area.

<script>
  jQuery(document).ready(function(){
    jQuery(".pa_toggle_buttons").each(function(){
        jQuery(this).on("click", function(){
            var id = jQuery(this).attr("href");
            if(jQuery(id).hasClass("et_pb_toggle_close")){
                jQuery(id).children(".et_pb_toggle_title").click();
                
            }
        })
    })
})
</script>

Last updated Aug 29, 2022 @ 11:40 pm

Subscribe

Each month we send out a roundup email newsletter with the latest tutorials, product updates, helpful resources, and any other industry or personal news. Occasionally we send an extra separate email here and there if we just can’t wait! So that’s what you will get if you subscribe, and you can always unsubscribe at any time if you just can’t take it anymore :)

Blog Post Optin

Please share this post!

Nelson Lee Miller (aka The Divi Teacher)

Nelson is the owner of Pee-Aye Creative in the beautiful state of Pennsylvania. He loves helping small businesses, exploring outdoors, building websites with Divi, and teaching others.

Leave A Response!

By commenting you agree to our Blog & YouTube Comments Policy

17 Comments

  1. Mad Dog

    I can try it, but can this work or be modified to work with Tabs? I want to create links that go to the Tab and open it. The tutorials I’m finding are pretty complicated and messy and this would be so much easier.

    THANKS!

    Reply
    • Nelson Lee Miller (aka The Divi Teacher)

      Tabs would be a little different, we will check on this for a future tutorial. Our Divi Tabs Maker does have a deeplinking feature for that though! 🙂

      Reply
  2. tom

    I have followed the directions. The button is on one page and the toggle is on another.
    When I click on the button. it goes to the page with the toggle, and then scrolls to the toggle.

    The toggle does not open.

    What am I missing?

    Reply
  3. Gaston

    Thanks Nelson, it works perfectly when using a button.

    Let’s say that I’m using a full width header module with its 2 buttons, or an hyperlink in a text module or in a toggle, is there a way to make it work ?

    Thanks,

    Gaston

    Reply
  4. Sarah Cauble

    Is it possible to achieve this when linking from another page? I tried it with this code plus the name of the page in the link URL and couldn’t get it to work, so I’m curious. Thanks in advance!

    Reply
    • Hemant Gaba

      Hi Sarah!

      We’re working on it and should update the guide soon.

      Thank you!

      Reply
  5. Yoli

    Hi Nelson,

    Great tutorial thanks, can this also work for sub-menu items, cause I cant seem to make the toggles open, maybe Im doing something wrong.

    Reply
  6. Jr

    Instead of a button I created menu links to trigger the toggles and find that on desktop it works exactly the same as using a button but on mobile it scrolls me to the toggle but does not expand. I’m not sure what I’m missing.

    Reply
  7. Bülent

    Hey Nelson,

    I tried that with Avada-theme but it didn’t. Do you think it should, or did I do something wrong?

    Reply
  8. David Harmony

    How would we open a specific section (toggle?) within an Accordion?

    Did not find this guidance in your tutorials home page. Please consider guiding us on a future tutorial?

    Use case: from a different page, link to the page with the Accordion and pop-open a section based on the anchor reference.
    myotherpage: etc …

    thank you for your wonderful talent share

    Reply
    • Nelson Lee Miller (aka The Divi Teacher)

      It’s quite tricky, as the Accordion module does not have any CSS or ID fields per individual toggle item within the module. Because of that, we opted not to do a tutorial on that due to the complexity for most users.

      Reply
  9. Madeline Edwards

    Hi, is there a way to do this using linked text instead of a button? I couldn’t get it to work with the linked text since there is’t a place to add CSS class in each link.

    Reply
    • Hemant Gaba

      Hi Madeline!

      The linked HTML should be as follow:

      My text

      Let me know how it goes!

      Reply

Submit a Comment

Your email address will not be published.

Recent Posts

0

Your Cart