-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
42 lines (31 loc) · 868 Bytes
/
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
42
const form = document.getElementById("todo-form");
const input = document.getElementById("todo-input");
const todoUL = document.getElementById("todo-ul");
form.addEventListener("submit", (e) => {
e.preventDefault();
addTodo();
});
function strikethroughText(li) {
li.classList.add("strike-through-text");
}
function deleteLi(li) {
li.remove();
}
function addTodo() {
let todoText = input.value;
let todoLi = document.createElement("li");
todoLi.addEventListener("click", (e) => {
e.preventDefault();
strikethroughText(todoLi);
});
todoLi.addEventListener("contextmenu", (e) => {
e.preventDefault();
deleteLi(todoLi);
});
todoLi.innerHTML = todoText;
todoUL.appendChild(todoLi);
cleanInput();
}
function cleanInput() {
input.value = "";
}