-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (31 loc) · 998 Bytes
/
script.js
File metadata and controls
32 lines (31 loc) · 998 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
const title = document.querySelectorAll("h1.title");
const inp = document.querySelector("input");
const list = document.querySelector("ul");
const btn = document.querySelector("button");
for (let i = 0; i < title.length; i++) {
title[i].addEventListener("click", e => {
if (e.target.style.textDecoration == ""){
e.target.style.textDecoration = "underline blue 5px";
} else{
e.target.style.textDecoration = "";
}
})
}
inp.addEventListener("keydown", e => {
if (e.key == "Enter"){
const li = document.createElement("li");
li.textContent = inp.value;
inp.value = "";
list.append(li);
li.addEventListener("click", e => {
e.target.remove();
})
}
})
btn.addEventListener("click",e => {
const listLength = Array.from(list.children);
for (let i = 0; i < listLength.length; i++) {
listLength[i].remove();
inp.value = "";
}
})