Shopify themes, liquid, logos, and UX
I’m actually quite lost on “2.” to be honest. I’ve never added a class and I’m not sure where or how it should be typed. I’ve been looking into articles and videos but I’m drawing a blank.
I've refactored your JS code a bit and added the required functionality:
window.addEventListener('DOMContentLoaded', () => {
if (window.matchMedia('(min-width: 750px)').matches) {
return
}
const collapse = (heading) => {
heading.classList.add('block-collapsed')
heading.setAttribute('aria-expanded', 'false')
}
const expand = (heading) => {
heading.classList.remove('block-collapsed')
heading.setAttribute('aria-expanded', 'true')
}
const handleClick = (event) => {
const heading = event.target
if (heading.classList.contains('block-collapsed')) {
headings.forEach(collapse)
expand(heading)
} else {
collapse(heading)
}
}
const headings = document.querySelectorAll('.grid .footer-block__heading');
headings.forEach((heading, index) => {
heading.setAttribute('role', 'button')
heading.setAttribute('tabindex', '0')
heading.nextElementSibling.setAttribute('id', `footer-block-index-${index}`)
heading.setAttribute('aria-controls', `footer-block-index-${index}`)
collapse( heading );
heading.addEventListener('click', handleClick )
})
})
Sorry for the late reply, I didn’t receive a notification til this morning. Exactly where do I paste this?
Edit: I attempted it in “global.js” and got inconsistent results. They both were possible of opening at the same time but closing one sometimes closed both. At times the button was unresponsive as well as trigger the wrong menu.
Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025