-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscript.js
41 lines (29 loc) · 1.08 KB
/
script.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
const tableKey = 'table';
let table;
let tableDemo = {
'SpongeBob SquarePants': {
'phoneNumber': '123456789'
'addrress': '104 Bikini Bottom Drive, Bikini Bottom, Under Water, 12345'
}
}
let refreshDOMTable = () => {
let tableKeys = Object.keys(table);
let tableContainer = document.getElementById('contactsTable');
let oldTableBody = document.getElementById('tableBody');
tableContainer.removeChild(oldTableBody);
let newTableBody = document.createElement('span');
newTableBody.id = 'tableBody';
for (let i=0; i<tableKeys.length; i++) {
let currentRow = document.createElement('div');
let currentNameCol = document.createElement('div');
let currentDeleteBtn = document.createElement('div');
currentRow.className = 'tableRow';
currentNameCol.className = 'tableColumn';
currentDeleteBtn.className = 'tableColumn delete';
currentNameCol.innerHTML = tableKeys[i];
currentDeleteBtn.innerHTML = '<i class="fas fa-trash-alt"></i>';
currentRow.appendChild(currentNameCol);
currentRow.appendChild(currentDeleteBtn);
newTableBody.appendChild(currentRow);
}
}