Link to open accordion on another page breaks ability to collapse item

I’m using the script that was provided here on the support forum to link to another page with an accordion and open it, which is working great other than it breaks the ability to collapse that specific accordion. Is there a workaround that allows me to link to and open an accordion on another page while still retaining the ability to then close it?

Here’s the script I’m using:

 jQuery(document).ready(function($) {
      var hash = window.location.hash;
      var accBody = $(hash + '.x-accordion-group').find('.x-accordion-body');

      if (hash != '') {
        $(accBody).each(function(){
            $(this).removeClass('collapse');
            $(this).addClass('in').css('height', 'auto');
        });
      }
});

This is exactly what I’m looking to do, but when I try your link it says the page doesn’t exist or is private?

Sorry, must have copied that in wrong. Here you go:

Hmm…that link does the same thing. Something with the forum. Here’s the code I used. Just give the accordion item a unique class name and then link to it like this: yoursite.com/yourpage/#unique-class-name-here

/* Open Accordion from Link */
jQuery(function($){
  
  $(document).ready(function() {
    var tabnum = location.href.split("#").slice(-1)[0] ;
    if(window.location.href.indexOf("#") > -1) {
      x_scroll_to_tab($, $('.x-accordion .'+tabnum+'>div>a') );
      }
  });

});

function x_scroll_to_tab($, tab_nav) {
            $(tab_nav).click();
	          $('html,body').animate({scrollTop: $(tab_nav).offset().top - ( $('.x-navbar').height() + 100 )},700 ,'swing');
}

Hi there,

I checked the code and it does not prevent the closing of the current tab. Would you please kindly get back to us with the URL/User/Pass of your website using the Secure Note functionality of the post and give us exact page you used the code in?

Please kindly consider that this is out of our support scope and we will do our best to make it work for your case but it is not a feature which is officially supported and is pure customization.

Thank you for your understanding.