-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
50 lines (41 loc) · 1.22 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
40
41
42
43
44
45
46
47
48
49
50
const submitForm = document.querySelector(".add");
const addButton = document.querySelector(".add-todo");
const todoList = document.querySelector(".todos");
const list = document.querySelectorAll(".todos li");
const dayTitle = document.querySelector("#dayName");
const lang = navigator.language;
// Setting in a New day
let date = new Date();
let dayName = date.toLocaleString(lang, {
weekday: "long",
});
dayTitle.innerHTML = dayName;
let listLenght = list.lenght;
const generateTempalate = (todo) => {
const html = `<li>
<input type="checkbox" id="todo_${listLenght}">
<label for="todo_${listLenght}">
<span class="check"></span>
${todo}
</label>
<i class="far fa-trash-alt delete"></i>
</li>`;
todoList.innerHTML += html;
};
function addTodos(e) {
e.preventDefault();
const todo = submitForm.add.value.trim();
if (todo.length) {
listLenght = listLenght + 1;
generateTempalate(todo);
submitForm.reset();
}
}
submitForm.addEventListener("submit", addTodos);
addButton.addEventListener("click", addTodos);
function deleteTodos(e) {
if (e.target.classList.contains("delete")) {
e.target.parentElement.remove();
}
}
todoList.addEventListener("click", deleteTodos);