-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.html
131 lines (118 loc) · 3.25 KB
/
cart.html
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#container{
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
width: 50%;
margin-left: 50%;
}
#container>div{
border: 1px solid rgb(215, 206, 206);
display: flex;
}
#container>div>img{
width: 100px;
height: 100px;
}
#container>div>p{
margin: auto;
margin-left: 10px;
font-size: 16px;
width: 50%;
}
#container>div>h2{
margin: auto;
margin-left: -30px;
}
h1{
color: #00afef;
padding-left: 30px;
font-size: 20px;
}
#total{
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
width: 50%;
margin-left: 50%;
display: flex;
justify-content: space-between;
}
#total>p{
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
margin-left: 20px;
margin: 25px;
font-size: 20px;
}
#total>button{
background-color: #00afef;
height: 50px;
border: 0;
display: block;
border-radius: 5px;
margin-bottom: 20px;
margin-top: 15px;
margin-right: 10px;
font-size: 18px;
}
#total>button>a{
text-decoration: none;
}
#but{
background-color: #00afef;
color: white;
height: 30px;
border: 0;
display: block;
border-radius: 5px;
margin-bottom: 20px;
margin-top: 35px;
margin-right: 10px;
font-size: 18px;
}
</style>
</head>
<body>
<div id="container">
<div><h1>My Cart</h1></div>
</div>
<div id="total">
<p></p>
<button><a href="payment.html">CONTINUE</a></button>
</div>
</body>
</html>
<script>
var cartData=JSON.parse(localStorage.getItem("cart"));
console.log(cartData);
var total=cartData.reduce(function (sum,elem,index,arr){
return sum+(+elem.price);
},0);
console.log(total)
document.querySelector("p").innerText= "₹"+total
cartData.map(function(elem,index){
var box=document.createElement("div")
var imag=document.createElement("img")
imag.src=elem.img
var nam=document.createElement("p")
nam.innerText=elem.name
var pric=document.createElement("h2")
pric.innerText="₹"+elem.price
var btn=document.createElement("button");
btn.setAttribute("id","but")
btn.innerText="delete";
btn.addEventListener("click",function(){
deleteitem(elem,index)
});
box.append(imag,nam,pric,btn);
document.querySelector("#container").append(box);
});
function deleteitem(elem,index){
cartData.splice(index,1)
localStorage.setItem("cart",JSON.stringify(cartData))
window.location.reload()
}
</script>