At this point, you can listen for click events anywhere inside .accordion-container. The event.target will be the item you clicked on.
Making the accordions work
If the user clicked inside .accordion__header, we want to show (or hide) the accordion. If the user clicked inside .accordion__content, we want to ignore those clicks.
To do this, we can check if .accordion__header is an ancestor of the event.target.
accordionContainer.addEventListener('click', event => {
const accordionHeader = event.target.closest('.accordion__header')
if (accordionHeader) {
console.log('From header. Close accordion!')
} else {
console.log('Not from header. Ignore.')
}
})
If .accordion__header is an ancestor of event.target, we need to add (or remove) the is-open class to .accordion. From the HTML, we know .accordion is the parentElement of .accordion__header.