How to make collapsible row close one at a time

Solved

How to make collapsible row close one at a time

undercoverfresh
Excursionist
138 0 19

I’m looking to make the collapsible row close automatically after another one opens for mobile and desktop 

 

URL knmb1c-pf.myshopify.com

password samurai 

Accepted Solution (1)

Moeed
Shopify Partner
7050 1899 2325

This is an accepted solution.

Hey @undercoverfresh 

 

Follow these Steps:

1) Go to Online Store
2) Edit Code
3) Find theme.liquid file

4) Add the following code in the bottom of the file above </body> tag

<script>
document.addEventListener("DOMContentLoaded", function () {
  const accordions = document.querySelectorAll(".product__accordion details");

  accordions.forEach((accordion) => {
    accordion.addEventListener("click", function (event) {
      event.stopPropagation();

      accordions.forEach((otherAccordion) => {
        if (otherAccordion !== this) {
          otherAccordion.removeAttribute("open");
        }
      });
    });
  });
});
</script>

 

If I managed to help you then, don't forget to Like it and Mark it as Solution!

 

Best Regards,
Moeed

- Need a Shopify Specialist? Chat on WhatsApp

- Get a quick Shopify quote – Click here!

- Custom Design | Advanced Coding | Store Modifications


View solution in original post

Reply 1 (1)

Moeed
Shopify Partner
7050 1899 2325

This is an accepted solution.

Hey @undercoverfresh 

 

Follow these Steps:

1) Go to Online Store
2) Edit Code
3) Find theme.liquid file

4) Add the following code in the bottom of the file above </body> tag

<script>
document.addEventListener("DOMContentLoaded", function () {
  const accordions = document.querySelectorAll(".product__accordion details");

  accordions.forEach((accordion) => {
    accordion.addEventListener("click", function (event) {
      event.stopPropagation();

      accordions.forEach((otherAccordion) => {
        if (otherAccordion !== this) {
          otherAccordion.removeAttribute("open");
        }
      });
    });
  });
});
</script>

 

If I managed to help you then, don't forget to Like it and Mark it as Solution!

 

Best Regards,
Moeed

- Need a Shopify Specialist? Chat on WhatsApp

- Get a quick Shopify quote – Click here!

- Custom Design | Advanced Coding | Store Modifications