Skip to content

Instantly share code, notes, and snippets.

@Garconis
Last active September 14, 2020 16:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Garconis/440d5e8f9a42b762c1ae29e6de46f180 to your computer and use it in GitHub Desktop.
Save Garconis/440d5e8f9a42b762c1ae29e6de46f180 to your computer and use it in GitHub Desktop.
Divi | Open toggle from another page (or same page) based on toggle ID and URL hash
// courtesy: https://bernadot.com/divi-theme-how-to-open-toggled-modules-with-a-url-hashtag/
(function($){
// open Toggle module if URL in address bar has same hash
$(window).load(function(){
var et_hash = window.location.hash;
if(window.location.hash) {
$( '.et_pb_toggle' + et_hash )
.removeClass('et_pb_toggle_close')
.addClass('et_pb_toggle_open')
}
});
// open Toggle module if URL that was clicked on the same page has the same hash
$(".sub-menu a").click(function(){
var et_hash = this.hash;
if(this.hash) {
// close other toggles before opening the new one
$('.et_pb_toggle')
.removeClass('et_pb_toggle_open')
.addClass('et_pb_toggle_close');
// open the toggle that has the hash
$( '.et_pb_toggle' + et_hash )
.removeClass('et_pb_toggle_close')
.addClass('et_pb_toggle_open')
}
});
})(jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment