-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (27 loc) · 801 Bytes
/
Copy pathapp.js
File metadata and controls
31 lines (27 loc) · 801 Bytes
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
let itemList = [];
document.getElementById('btn').addEventListener('click', addItem);
function addItem() {
let item = document.getElementById('todo').value;
if (item.trim() !== "") {
itemList.push(item);
document.getElementById('todo').value = "";
getItem();
}
}
function getItem() {
let emptystr = "";
let sno = 0;
itemList.forEach(function(value, index) {
sno += 1;
emptystr += `<tr>
<td>${sno}</td>
<td>${value}</td>
<td><button onclick="removeItem(${index})">Remove</button></td>
</tr>`;
});
document.getElementById('tbl').innerHTML = emptystr;
}
function removeItem(index) {
itemList.splice(index, 1);
getItem();
}