Kind of a special case of this: Change CSS of the clicked element.
If I have some divs like this:
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
I know I can assign a function to each parent div like:
const parent = document.querySelectorAll('.parent');
if(parent.length){
for (let l of parent){
l.addEventListener('click', (e)=>{
l.classList.toggle('visible')
})
}
}
But how can I toggle the class .visible for the child div when the parent is clicked? Or alternatively add visibility:visible to the child div style.
Many thanks!