-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwishlistpage.js
95 lines (73 loc) · 2.95 KB
/
wishlistpage.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var wishlistarr = JSON.parse(localStorage.getItem("wishlist")) || []
var cartarr = JSON.parse(localStorage.getItem("cartitem"))
var wishtocart= wishlistarr
console.log(wishlistarr)
diswish(wishlistarr);
function diswish(wishlistarr)
{
wishlistarr.map(function (elem,index){
var div1 = document.createElement("div")
div1.setAttribute("id","box1")
var div2 =document.createElement("div")
var avatar = document.createElement("img");
avatar.setAttribute("src",elem.image_url);
avatar.setAttribute("class","productimage");
var h4 = document.createElement("h6");
h4.textContent = elem.brand;
h4.setAttribute("class","productbrand");
var h5 = document.createElement("p");
h5.textContent = elem.name;
h5.setAttribute("class","productname");
var add = document.createElement("button");
add.textContent="cart ";
add.setAttribute("class","bag");
add.addEventListener("click",function()
{
addbag(elem,index)
})
var i = document.createElement("i");
i.classList.add("bi", "bi-bag-fill");
add.append(i);
var btn = document.createElement("button");
btn.textContent = "";
btn.setAttribute("class","deltebtn")
btn.addEventListener("click",function()
{
delcart(index)
});
var i = document.createElement("i");
i.classList.add("bi", "bi-trash-fill");
btn.append(i);
var cost = document.createElement("p");
cost.textContent = `INR ${elem.price}`;
cost.setAttribute("class","productcost");
// var div3 = document.createElement("div");
// div3.setAttribute("id","btndel")
// div3.append(cost,btn);
// div2.append()
var baganddel = document.createElement("div");
baganddel.setAttribute("class","bagAnddel");
baganddel.append(add,btn);
div1.append(avatar,h4,h5,cost,baganddel);
document.querySelector("#blockelem").append(div1);
});
}
function delcart(index) {
wishlistarr.splice(index, 1)
localStorage.setItem("wishlist", JSON.stringify(wishlistarr))
diswish(wishlistarr)
location.reload()
}
function removeall(){
document.querySelector("#blockelem").textContent = "";
}
function addbag(elem,index)
{
wishlistarr.splice(index,1)
console.log(wishlistarr)
localStorage.setItem("wishlist", JSON.stringify(wishlistarr))
cartarr.push(elem)
localStorage.setItem("cartitem",JSON.stringify(cartarr))
console.log(cartarr)
location.reload()
}