My issue is that the add to cart button on my website is not responding properly. I have implemented JavaScript on the add to cart button, where I have assigned an attribute called data-product with a value of {{product.id}}.
var updateBtns = document.getElementsByClassName('update-cart')
for (var i = 0; i < updateBtns.length; i++) {
updateBtns[i].addEventListener('click', function() {
var productId = this.dataset.product
var action = this.dataset.action
console.log('productId:', productId, 'action:', action)
})
}
<div class="card-body">
<h5 class="card-title fw-bold text-uppercase">{{product.name}}</h5>
<p class="card-text">
<h4 style="font-size: 1rem; padding: 0.3rem;
opacity: 0.8;">$ {{product.price}} </h4>
</p>
<button data-product={{product.id}} data-action="add" class="btn btn-outline-secondary add-btn update-cart">ADD TO CART</button>
</div>
</div>
Despite clicking on the Add to Cart button multiple times, nothing is being displayed in the console.