-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
76 lines (49 loc) · 1.7 KB
/
app.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
class UI {
static addRow() {
const element = document.createElement('div');
element.setAttribute('class','wrap');
const html = `
<input type="text" id="title" name=[calories] class="form-control" placeholder="Additional Colories">
<a href="" class="add btn btn-primary"><i class="fas fa-plus"></i></a>
<a href="" class="remove btn btn-primary"><i class="fas fa-minus"></i></a>
`;
element.innerHTML = html;
document.querySelector('form').append(element);
element.querySelector('.add').addEventListener('click', (e) => {
this.addRow(e.target);
e.preventDefault();
});
element.querySelector('.remove').addEventListener('click', (e) => {
element.remove();
this.getTotals();
e.preventDefault();
});
element.querySelector('input').addEventListener('input', (e) => {
this.getTotals();
});
}
static deleteRow() {
if(el.classList.contains('delete')) {
el.parentElement.parentElement.remove();
this.getTotals();
}
}
static getTotals() {
const forms = document.querySelectorAll('form');
const form = forms[0];
let sum =0;
[...form.elements].forEach((input) => {
sum += parseFloat(input.value);
//console.log(input.value);
});
document.querySelector('.total h3 span').textContent = sum;
}
}
document.querySelector('.add').addEventListener('click', (e) => {
UI.addRow(e.target);
e.preventDefault();
//console.log(this);
});
document.querySelector('input').addEventListener('input', (e) => {
UI.getTotals(e.target);
});