Help with my FAQ Accordian

Help with my FAQ Accordian

coffeesolutions
Visitor
1 0 0

Hi, I'm having trouble with my FAQ. I want answers to automatically close when someone clicks on a new question. (only one answer open at a time). I'm using the whisk theme, and here is a link to the page in question: https://www.brandroastsupply.com/pages/faq

 

 

Any help would be appreciated, Thanks!

Replies 2 (2)

SafeerAhmed
Excursionist
43 9 11

Hey,
search for questions.liquid and paste it or paste it in theme.liquid just before the closing </body> tag

<script>
const faqs = document.querySelectorAll('details');
faqs.forEach((faq) => {
    faq.addEventListener('click', function() {
        faqs.forEach((otherFaq) => {
            if (otherFaq !== faq) {
                otherFaq.removeAttribute('open');
            }
        });
    });
});
</script>

 

Safeer Ahmed | Shopify Expert & Developer
Specialist in Shopify Development & Custom Shopify Solutions
Let's connect:safeerahmed23901@gmail.com
If my response helped, give it a like & mark it as a solution!

namphan
Shopify Partner
2678 348 396

Hi @coffeesolutions,

You want it to be grouped, like 'WHO ARE WE AND WHO ARE WE FOR?' or 'OUR COFFEE' or whatever question is displayed, the other question will be closed?

Coffee tips fuels my dedication.
Shopify Development Service
PageFly Page Builder Optimize your Shopify store (Free plan available)
Need help with your store? namphan992@gmail.com