From 7b6b7cc282b4fe217c29d8cab303550fb9249e31 Mon Sep 17 00:00:00 2001 From: Janeychi Date: Tue, 7 Mar 2023 18:34:35 +0100 Subject: [PATCH] add new file --- .../janefrancesOkeke/DOM/Vendorpage.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 submissions/janefrancesOkeke/DOM/Vendorpage.js diff --git a/submissions/janefrancesOkeke/DOM/Vendorpage.js b/submissions/janefrancesOkeke/DOM/Vendorpage.js new file mode 100644 index 000000000..be8c407e2 --- /dev/null +++ b/submissions/janefrancesOkeke/DOM/Vendorpage.js @@ -0,0 +1,33 @@ +const addCart = document.querySelectorAll(".addToCartButton"); +const notification = document.getElementsByClassName("notificationDot"); +console.log(notification); +let notificationCount = 0; + +for (let addToCartButton of addCart) { + console.log(addToCartButton); + + addToCartButton.addEventListener("click", function () { + if (addToCartButton.innerText === "Add to Cart") { + addToCartButton.style.backgroundColor = "#A5A5A5"; + addToCartButton.style.color = "rgba(255, 255, 255, 1)"; + addToCartButton.style.border = "none"; + addToCartButton.innerHTML = + 'Remove'; + notification[0].style.display = "inline-block"; + notificationCount++; + notification.innerText = notificationCount; + + } else if (addToCartButton.innerText === "Remove") { + addToCartButton.style.backgroundColor = "#fff"; + addToCartButton.style.color = "#ad4c4c"; + addToCartButton.style.border = "1px solid #ad4c4c"; + addToCartButton.innerText = "Add to Cart"; + notificationCount--; + notification.innerText = notificationCount; + } + + if (notificationCount <= 0) { + notification[0].style.display = "none"; + } + }); +} \ No newline at end of file