-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
36 lines (31 loc) · 801 Bytes
/
Copy pathscript.js
File metadata and controls
36 lines (31 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
32
33
34
35
36
// Get elements
const input = document.getElementById("input");
const list = document.getElementById("list");
// Add task
function addTask() {
// Create new list item
const li = document.createElement("li");
const task = document.createTextNode(input.value);
li.appendChild(task);
// Create delete button
const button = document.createElement("button");
button.innerHTML = "×";
button.onclick = function() {
li.remove();
}
li.appendChild(button);
// Add list item to list
if (input.value === "") {
alert("Please enter a task");
} else {
list.appendChild(li);
input.value = "";
}
}
// Press enter to add task
input.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
document.getElementById("addBtn").click();
}
});