Shopify filters Auto-Close Previous Filters

Shopify filters Auto-Close Previous Filters

Digital_Imran
Shopify Partner
280 2 40

Hello everyone, I need a little help. On my Shopify store, when I open a filter, such as the price filter, and then open another filter like the color filter, the price filter remains open. I want the filters to work so that when I open one, the previously opened filter closes automatically. Is there a code to achieve this?

Any help would be greatly appreciated!

My store URL: https://myperfectwear.com/

Problem Solved? ✔Accept and Like solutions to help future merchants.

Do you need high converting Shopify store? with customized graphical banners, hire me.
Message me now to get started. My response time is lightning fast.
Replies 5 (5)

Kyle_liu
Shopify Partner
365 46 60

Hi @Digital_Imran 

 

add this script:

document.addEventListener('DOMContentLoaded', function() {

  const detailsElements = document.querySelectorAll('details.accordion');

  detailsElements.forEach(detail => {
    detail.addEventListener('click', function() {
      detailsElements.forEach(d => {
          d.removeAttribute('open');
          d.setAttribute('aria-expanded', 'false');
        }
      });

      if (detail.hasAttribute('open')) {
        detail.setAttribute('aria-expanded', 'true');
      } else {
        detail.setAttribute('aria-expanded', 'false');
      }
    });
  });
});
If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me Email Me Buy Me A Coffee
Kyle_liu
Shopify Partner
365 46 60

1734511985983-20241218_163518.gif

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me Email Me Buy Me A Coffee
Digital_Imran
Shopify Partner
280 2 40

Hello @Kyle_liu thanks for replying , I added my comment I will highly appreciate your response

Problem Solved? ✔Accept and Like solutions to help future merchants.

Do you need high converting Shopify store? with customized graphical banners, hire me.
Message me now to get started. My response time is lightning fast.
Digital_Imran
Shopify Partner
280 2 40

Thank you so much @Kyle_liu . Where I should add this script ? Can you please tell me . 🙂

Problem Solved? ✔Accept and Like solutions to help future merchants.

Do you need high converting Shopify store? with customized graphical banners, hire me.
Message me now to get started. My response time is lightning fast.
Digital_Imran
Shopify Partner
280 2 40

Hello

Thank you so much @Kyle_liu . Where should I add this script? Can you please tell me .

 

 

Problem Solved? ✔Accept and Like solutions to help future merchants.

Do you need high converting Shopify store? with customized graphical banners, hire me.
Message me now to get started. My response time is lightning fast.