Can someone help me create a button that toggles between displaying block and display none when clicked?
I've been trying to use Classlist.toggle with JavaScript, but I'm not sure if I have the correct classes targeted.
let showCart = document.querySelector(".product-container");
let cart = document.querySelector(".cart");
cart.addEventListener("click", () => [
showCart.classList.toggle(".cart-show")
]);
.cart {
margin-left: 85rem;
}
.cart-show {
display: block;
}
.cart a {
filter: invert(43%) sepia(32%) saturate(310%) hue-rotate(347deg) brightness(90%) contrast(88%);
width: 0rem;
}
span {
position: absolute;
margin-left: 2rem;
margin-top: -1.3rem;
}
<li class="nav-item cart">
<a class="nav-link">
<img src="./assets/icons/cart shopping icon.svg" alt="cart icon"><span>0</span></a>
</li>
<div class="product-container">
<div class="product-header">
<h5 class="product-title"></h5>
<h5 class="price"></h5>
<h5 class="quantity"></h5>
<h5 class="total"></h5>
</div>
<div class="products">
</div>
</div>