Shopify themes, liquid, logos, and UX
I'm using the Dawn theme and want to customize the product page's collapsible menus (Description, Care, Help) so that only one menu is open at a time. This should work on both mobile and desktop views. When a tab is opened, the previously opened tab should automatically close.
website: https://the-rugged.com/
password: rugged
Solved! Go to the solution
This is an accepted solution.
Hi @Sivadarshan
let add this JS code to your file header.liquid:
<script>
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.product__accordion details').forEach((detail) => {
detail.addEventListener('toggle', (event) => {
if (detail.open) {
// Close all other details elements except the one just opened
document.querySelectorAll('.product__accordion details').forEach((otherDetail) => {
if (otherDetail !== detail && otherDetail.open) {
otherDetail.open = false;
}
});
}
});
});
});
</script>
Hi @Sivadarshan ,
Please open main-product.liquid , locate details tag and insert the below code :-
<script>
document.addEventListener("DOMContentLoaded", function ()
{
const collapsibles = document.querySelectorAll('details');
collapsibles.forEach((el) =>
{
el.addEventListener('toggle', function ()
{
if (el.open)
{
collapsibles.forEach((other) =>
{
if (other !== el && other.open)
{
other.removeAttribute('open');
}
});
}
});
});
});
</script>
Please let me know if it works !
Thanks
This is an accepted solution.
Hi @Sivadarshan
let add this JS code to your file header.liquid:
<script>
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.product__accordion details').forEach((detail) => {
detail.addEventListener('toggle', (event) => {
if (detail.open) {
// Close all other details elements except the one just opened
document.querySelectorAll('.product__accordion details').forEach((otherDetail) => {
if (otherDetail !== detail && otherDetail.open) {
otherDetail.open = false;
}
});
}
});
});
});
</script>
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025