-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomeQuantityToggle.js
30 lines (24 loc) · 1016 Bytes
/
homeQuantityToggle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;
};