Last active
September 14, 2020 16:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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