Click a Divi Content Toggle Module by a Link

Written by Dan Mossop

The Divi Content Toggle Module by Divi Extended lets you create toggle buttons for pricing tables, allowing users to easily switch between different pricing options. Normally the user needs to click on the toggle button to switch between the pricing tables. If you'd like to be able to have users follow a link to the "clicked" view of the Divi Content Toggle Module, here's how to do it.

Toggle a Divi Content Toggle Module by Link using jQuery

First, give your Content Toggle Module a CSS ID, such as "mytoggle" at:

Content Toggle Settings > Advanced > CSS ID & Classes > CSS ID

Then add the following jQuery code to your site: 

<script>
/* Open a Divi Content Toggle Module by Divi Extended when Linking to the Page */
/* Src: https://divibooster.com/toggle-a-divi-content-toggle-by-a-link/ */
jQuery(function($) {
	setTimeout(function(){
		var query = window.location.search.substring(1);
		var params = query.split('&');
		var toggle_id = '';
		for (var i = 0; i < params.length; i++) {
			var param = params[i].split('=');
			if (param[0] !== undefined && param[1] !== undefined) {
				param[1] = decodeURIComponent(param[1]);
				if (param[0] === 'toggle' && /^[a-zA-Z0-9]+$/.test(param[1])) {
					toggle_id = param[1];
				}
			}
		}
		if (toggle_id !== '') {
			$('#'+toggle_id+'.dipl_content_toggle .dipl_toggle_button .dipl_toggle_field').trigger('click');
		}
	}, 100);
});
</script>

Now you'll be able to trigger a click on the toggle when linking to the page containing it, by including a "toggle" parameter in the URL with the ID of your toggle. So, for example, your link to the page might look something like this:

https://divibooster.com/some-page/?toggle=mytoggle

Enhance Your Divi Skills with Advanced Features!

Transform your Divi site with the Divi Booster, offering hundreds of new features to boost your design capabilities. Streamline your content toggles and more with easy customization options.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

2 Comments

  1. Super helpful when dealing with dozens of FAQs. Have an index with questions on the top of the page, with jumplinks to the question and answer in the toggle modules below. Great for user experience and keeping things tidy.

    Reply
    • I'm glad it's proving helpful, Asad. Thanks for the feedback – much appreciated!

      Reply

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

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

We may earn a commission when you visit links on our website.