-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDOM.js
69 lines (57 loc) · 2.06 KB
/
DOM.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
let addButtons = Array.from(document.querySelectorAll("#add-button"));
let minusButtons = Array.from(document.querySelectorAll("#minus-button"));
let quantitys = Array.from(document.querySelectorAll("#quantity"));
let prices = Array.from(document.querySelectorAll("#price"));
let deletes = Array.from(document.querySelectorAll("#delete"));
let parents = Array.from(document.querySelectorAll("#parent"));
let hearts = Array.from(document.querySelectorAll("#heart"));
let arrOfQuantitys = [];
let arrOfPrices = [];
for(let i in quantitys){
arrOfQuantitys[i] = 1 ;
}
for(let i in prices ){
arrOfPrices[i] = +prices[i].innerHTML;
}
function updateTotal(){
let total = 0 ;
for(let i in quantitys)
total += arrOfPrices[i]*arrOfQuantitys[i];
document.getElementById('totale-price').textContent=`TOTALE PRICE : ${total} $`;
}
updateTotal();
//********************PLUS_BUTTON*********************************/
for(let i in addButtons){
addButtons[i].addEventListener("click",function(){
arrOfQuantitys[i]++;
quantitys[i].innerHTML = arrOfQuantitys[i];
updateTotal();
});
}
//********************MINUS_BUTTON*********************************/
for(let i in minusButtons){
minusButtons[i].addEventListener("click",function(){
if(arrOfQuantitys[i] > 1){
arrOfQuantitys[i]--;
quantitys[i].innerHTML = arrOfQuantitys[i];
updateTotal();
}
});
}
//********************DELETE_BUTTON*********************************/
for(let i in deletes){
deletes[i].addEventListener("click",function(){
arrOfQuantitys[i] = 0;
updateTotal();
parents[i].remove();
});
}
//********************HEART_BUTTON*********************************/
for(let i in hearts){
hearts[i].addEventListener("click",function(){
if(hearts[i].getAttribute('src') == "RESheartNull.png")
hearts[i].setAttribute('src','RESheartLike.png');
else
hearts[i].setAttribute('src','RESheartNull.png');
});
}