forked from premsg1610/TATA-CLiQ-Clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bag.js
75 lines (45 loc) · 2.24 KB
/
bag.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var bagItems = JSON.parse(localStorage.getItem("bagItems"))
console.log(bagItems)
// console.log("prem")
document.querySelector("#img").src = bagItems[bagItems.length-1].img_url
document.querySelector("#itemDetail").innerText = bagItems[bagItems.length-1].detail
document.querySelector("#itemPrice").innerText = "₹ "+ bagItems[bagItems.length-1].price
document.querySelector("#bagTotal1").innerText = "₹ "+ bagItems[bagItems.length-1].price
document.querySelector("#bagTotal2").innerText = "₹ "+ bagItems[bagItems.length-1].price
// document.querySelector("#bagTotal3").innerText = "₹ "+ bagItems[bagItems.length-1].price
document.querySelector("#bagTotal4").innerText = "₹ "+ bagItems[bagItems.length-1].price
document.querySelector("#btn1").addEventListener("click",myfunction);
function myfunction(){
window.location.href="checkout.html";
}
document.querySelector("#delet").addEventListener("click",removeItem);
function removeItem(){
// console.log(elem,index)
// cartData.splice(index,1)
// console.log(cartData)
// localStorage.setItem("cart",JSON.stringify(cartData))
document.querySelector("#maincontainer").style.display = "none"
document.querySelector("#emptyBox").style.display = "block"
// if we click remove item then it will remove but show only when we refresh our page
// to fix this we use this function:
// window.location.reload()
}
// bagItems.map(function(elem){
// var productBox = document.createElement("div")
// productBox.setAttribute("id","productbox")
// var imageBox = document.createElement("div")
// imageBox.setAttribute("id","productimg")
// var img = document.createElement("img")
// img.src = elem.img_url
// var productDetails = document.createElement("div")
// var p1 = document.createElement("p")
// p1.innerText = elem.detail
// p1.setAttribute("id","itemDetail")
// var p2 = document.createElement("p")
// p2.innerText = elem.price
// p2.setAttribute("id","itemPrice")
// productDetails.append(p1,p2)
// imageBox.append(img)
// productBox.append(imageBox,productDetails)
// document.querySelector("#itemsContainer").append(productBox)
// })