Open accordion tab from link

I want to link (within the same page) to a certain tab of a classic accordion element, so the browser scrolls down (I have this already solved using an onclick event handler), but it seems like several html classes are being added/removed to various divs when opening/closing tabs, so it’s kind of difficult to follow through. Any js code already created for the matter?

I see there’s an old post pertaining the matter, but since 2015, X has been heavily updated. Using X 5.2.2 and Cornerstone 2.1.3.

Thanks

Hi there,

Thanks for writing in.

Please check this latest implementation https://theme.co/apex/forum/t/link-to-specific-accordion-on-different-page/5302/10

Then update the code to this

jQuery ( document ).ready( function($){
  
var accordion_hash = window.location.hash.split('-');

if ( accordion_hash[0] !== '#accordion' && ( accordion_hash[1] == '' || accordion_hash[1] == undefined ) ) return false;

   var accordionElement = $('.x-accordion-heading').eq( parseInt( accordion_hash[1] ) - 1 ).find('.x-accordion-toggle');

console.log( accordionElement );

    var navbar = $('.x-navbar').outerHeight();
    var yloc = $( accordionElement ).offset().top - 160;

    $( accordionElement ).trigger('click');

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

Then you can simply link and start it with #accordion-1 instead of #accordion-0 from that thread.

Thanks!

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