Link to an Accordion Item

Hi,

I followed the topic, https://theme.co/apex/forum/t/link-to-an-open-accordion-item-that-is-closed-by-default/43045 to create a link to an accordion item.

Added the JS as mentioned in the link, added a unique id to the element but the link when clicked brings the user close to the accordion item, not open the item.

Please advise.

Thank you

Hello @Mangtum,

Thanks for writing in! To assist you with this issue, we’ll first need you to provide us with your URL. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

Regards.

Hello Rue,

Here are the details.

Thank you,
MG

Hi @Mangtum,

The code applicable for your setup is this,

jQuery (function($){
$(window).load ( function() {  

    if(window.location.hash) {
      var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
     
   
       var navbar = $('.x-navbar').outerHeight();
       var adminbar = $('#wpadminbar').outerHeight();
       
    $('#'+hash + '.x-accordion-group .x-accordion-toggle').trigger('click');
   
    var yloc = $('#' + hash).offset().top+navbar+adminbar;

    $('html, body').stop().animate({
        scrollTop: yloc
    }, 850);


}
    
} );

});

This should serve as the snippet, you may enhance it but we can’t provide support or cover it.

Thanks!

1 Like

Thank you Rad, that helped.

You’re more than welcome, glad we could help.

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.