Skip to content

Commit

Permalink
change btn text depending on quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
HectorVilas committed Apr 26, 2023
1 parent 1fa4f57 commit 29dc0b9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion modules/functions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function addToCart() {
const thisCard = this.closest('.shop-card');
const thisBtn = this;
const thisCardMainBtn = thisCard.querySelector('.shop-card-buy');
const itemId = thisCard.dataset.itemId;
const cart = document.querySelector('.nav-cart');
const cartCount = document.querySelector('.nav-cart-count');
Expand All @@ -19,4 +19,11 @@ export function addToCart() {
cart.style.backgroundImage = 'url(../media/images/icons/cart-active.png)';
cartCount.style.backgroundColor = '#1F604A';
};
if (newAmount === 0) {
thisCardMainBtn.textContent = 'Add to Cart';
thisCardMainBtn.removeAttribute('disabled', true);
} else {
thisCardMainBtn.textContent = `${newAmount} Item${newAmount > 1 ? 's' : ''} added`;
thisCardMainBtn.setAttribute('disabled', true);
}
}

0 comments on commit 29dc0b9

Please sign in to comment.