Based on the following HTML markup:
<div class='list-container'>
<button class="btn">More details </button>
</div>
<div class="details">Lorem ipsum lorem ipsum lorem ipsum</div>
I wrote the following JavaScript code:
let btn = document.querySelector('.btn');
let detailsContainer = document.querySelector('.details');
btn.addEventListener('click', function(e) {
e.preventDefault();
detailsContainer.classList.toggle('visible');
});
But I need to change the JS code to use the event delegation so that the eventListener gets added to the list-container instead of to the btn.
It's easy in jQuery, but how can I do it in vanilla JS?