-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
51 lines (40 loc) · 1.57 KB
/
app.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
51
const todoInput = document.querySelector('.todo-input');
const todoButton = document.querySelector('.todo-btn');
const todoList = document.querySelector('.todo-list');
todoButton.addEventListener('click', addTodo);
todoList.addEventListener('click', editTodo);
function addTodo(e){
e.preventDefault();
if(todoInput.value.length == 0){
alert("N'oubliez pas d'ajouter votre tâche");
}else{
const newTodo = document.createElement('li');
const contentTodo = document.createElement('div');
contentTodo.textContent = todoInput.value;
const editTodo = document.createElement('div');
const doneTodo = document.createElement('i');
doneTodo.classList.add('fas');
doneTodo.classList.add('fa-check');
doneTodo.classList.add('done-btn');
const deleteTodo = document.createElement('i');
deleteTodo.classList.add('fas');
deleteTodo.classList.add('fa-trash-alt');
deleteTodo.classList.add('delete-btn');
editTodo.appendChild(doneTodo);
editTodo.appendChild(deleteTodo);
newTodo.appendChild(contentTodo);
newTodo.appendChild(editTodo);
todoList.appendChild(newTodo);
todoInput.value = '';
}
}
function editTodo(e){
const item = e.target;
const toEdit = item.parentElement.parentElement;
if(item.classList.contains('delete-btn')){
toEdit.remove();
}
if(item.classList.contains('done-btn')){
toEdit.classList.toggle('done');
}
}