How to open a specific accordion tab on another page with a text link

I can’t find a way to open the tab of an accordion with a text link:

  • the link should refer to an accordion on another page.
  • It must be accompanied by a script that opens the tab.

I found something on the web, but it doesn’t work. My accordion is equipped with IDs and the script was suggested (in the footer of the corresponding page):

    <script>
        if (location.hash !== null && location.hash !== "") {
            $(location.hash + ".collapse").collapse("show");
        }

        $('a[href*="#accordion"]').on('click', event => {
            event.preventDefault();
            const hash = event.target.href.split('#')[1];
            $('#' + hash + ".collapse").collapse("show");
            const dest = $('#' + hash).prev().offset().top;
            $(document).scrollTop(dest);
        });
    </script>

Maybe it is due to a wrong bootstrap version? I am using Bootstrap 5 in the latest BLOCS version.

I’m not familiar with javascript and would be happy if someone here has a tip.

PS: my text links are http://institut.fisaflensburg.de/workshops/index.html#accordion-19212-item-1 and the framing div element has the ID “accordion-19212-item-1”

Hi @cziepluch

It is not always as straight forward as that.

I have a bric in the works that handles accordions and tabs, will open and scroll to the tab, and also allow you to define an anchor within a tab or accordion to scroll too.

Basically a revamp of a Bootstrap 4 version, that I made a few years back. But way more capable.

I was working on it again today, and is probably 90% ready for testing, before release.

2 Likes

Hey Pete,
that sounds great for me. I’ve read in previous posts that you have something in the works, but then found nothing in the store about it.
I’d love to be in the front row - and if I wasn’t so polite, I’d almost be pushing :wink:
But it’s supposed to be good. I’m very curious and happy to wait for this kind of technical help.
Where would I hear about it, do you post it here or should I watch the Blocs Builder store?

It will be on here and on 𝕏 @Blocs Builder, plus the store so take your pick.

I want to make sure it’s polished, it has some quirks at the moment.

1 Like

Hi Pete,
I wanted to ask you gently if you have made any progress so that you could make a prognosis. I still don’t want to push, I’m just still very interested and curious.

Closer than I was. As you can appreciate I work on these semi-part time. Most of it has been done, I want to improve some of it. Eg. I have a working bric already.

1 Like

That’s great, I’m glad to hear that and I think it’s just as commendable that it was first carefully developed and only then published. And of course my sincere respect for the fact that this Bric was not created in a comfortable 38-hour week.

It looks like the issue might be related to how Bootstrap 5 handles accordion functionality. The script you’re using is based on older versions of Bootstrap, and it might not be compatible with Bootstrap 5.

Hey Erik_90,
thanks for the hint. I would probably have to dive deeper into Bootstrap 5 and maybe I could clarify it that way.
But since I’m not a programmer, I’ll wait for Pete’s Bric - if that solves my problem, it’ll be better suited to my skills.