-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
39 lines (29 loc) · 1.15 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
function addItem() {
// get the todo-item-text value
let newItemText = document.getElementById('todo-item-text').value;
// check if the newItemText is empty
if (newItemText === '') {
alert('You cannot add an empty todo item you silly goose!');
return;
}
let todoList = document.getElementById('todo-list');
let newListItem = document.createElement('li');
newListItem.classList.add('todo-item');
let deleteButton = document.createElement('button');
deleteButton.classList.add('button-delete');
deleteButton.innerHTML = 'X';
deleteButton.setAttribute('onclick', 'deleteItem(this)');
newListItem.appendChild(deleteButton);
let itemPElement = document.createElement('span');
itemPElement.innerHTML = newItemText;
newListItem.appendChild(itemPElement);
let dateElement = document.createElement('span');
dateElement.classList.add('item-date');
dateElement.innerHTML = (new Date()).toDateString();
newListItem.appendChild(dateElement);
todoList.appendChild(newListItem);
}
function deleteItem(item) {
console.log(item.parentElement);
item.parentElement.remove();
}