I have about 20 products, each product has a button and description box. I have looped through added a click event listener that displays the product description box once the button is clicked.
How can I give the button the ability to hide the description box as well (i.e. toggle display)?
Here is my code:
const descriptionBtn = document.querySelectorAll('.desc-btn');
descriptionBtn.forEach((btn) => {
btn.addEventListener('click', (e) => {
descriptionBox = btn.nextElementSibling;
descriptionBox.style.display = "block";
});
});