export const homeQuantityToggle = (event, id, stock) => {
const currentCardElement = document.querySelector(`#card${id}`);
// console.log(currentCardElement);
const productQuantity = currentCardElement.querySelector(".productQuantity");
// console.log(productQuantity);
let quantity = parseInt(productQuantity.getAttribute("data-quantity")) || 1;
if (event.target.className === "cartIncrement") {
if (quantity < stock) {
quantity += 1;
} else if (quantity === stock) {
quantity = stock;
}
}
if (event.target.className === "cartDecrement") {
if (quantity > 1) {
quantity -= 1;
}
}
//todo Don't Forget To LIKE SHARE & SUBSCRIBE TO THAPA TECHNCIAL YOUTUBE CHANNEL 👉 https://www.youtube.com/thapatechnical
productQuantity.innerText = quantity;
console.log(quantity);
productQuantity.setAttribute("data-quantity", quantity.toString());
return quantity;
};
Comments
Post a Comment