-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
80 lines (53 loc) · 2.03 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
77
78
79
80
document.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('registrar');
const input = form.querySelector('input');
const submitButton = form.querySelector('button');
const mainDiv = document.querySelector('.main');
const ul = document.getElementById('invitedList');
const div = document.createElement('div');
const filterLabel = document.createElement('label');
const filterCheckBox = document.createElement('input');
//Click submit
submitButton.addEventListener('click', (e)=>{
// WAIT DON'T DO WHAT YOU NORMALLY DO
e.preventDefault();
//take what's inside input box
let inviteeName = input.value;
//display it in invitedList ul
ul.appendChild(createInviteeLI(inviteeName));
});
function createInviteeLI (name) {
// Create Invitee List Item
const invitee = document.createElement('li');
// Create Name Element
const nameEl = document.createElement('h4');
nameEl.innerText = name;
invitee.appendChild(nameEl);
// Create Label
const confirmedLabel = document.createElement('label');
confirmedLabel.innerText = 'Confirmed';
// Create and Append Checkbox to Label
const confirmedCB = document.createElement('input');
confirmedCB.type = "checkbox";
confirmedCB.name = 'cb-' + name;
confirmedLabel.appendChild(confirmedCB);
// Append Label to Invitee List Item
invitee.appendChild(confirmedLabel);
const removeButton = document.createElement('button')
removeButton.innerText = 'Remove';
removeButton.addEventListener('click', removeInviteeLI);
invitee.appendChild(removeButton);
return invitee;
}
function removeInviteeLI (e) {
// Grab which LI the button is part of
const clickTarget = e.target;
const li = clickTarget.parentNode;
const ul = li.parentNode;
// Remove the li from the ul
ul.removeChild(li);
}
//listen for the button click
//on button click add name, edit, remove, confirm to list element
//
});