-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 975 Bytes
/
index.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
const d = document,
$newTask = d.getElementById("newTaskInput"),
$tasksList = d.querySelector(".list-content");
function saveTask() {
localStorage.setItem("data", $tasksList.innerHTML)
}
function getTasks() {
$tasksList.innerHTML = localStorage.getItem("data");
}
getTasks();
d.addEventListener("submit", e => {
e.preventDefault();
if(e.target.matches("form")){
if (!$newTask.value) return alert("¿What do you have to do? Write it!");
let $li = d.createElement("li");
$li.innerHTML = $newTask.value;
let $delete = d.createElement("span");
$delete.innerHTML = "\u00d7";
$li.appendChild($delete);
$tasksList.appendChild($li);
}
$newTask.value = "";
saveTask();
})
d.addEventListener("click", e => {
if(e.target.matches("span")){
e.target.parentElement.remove();
}
if(e.target.matches("li")) {
e.target.classList.toggle("checked");
}
saveTask();
})