-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (24 loc) · 902 Bytes
/
script.js
File metadata and controls
28 lines (24 loc) · 902 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
const form = document.getElementById('todo-form');
const input = document.getElementById('todo-input');
const list = document.getElementById('todo-list');
form.addEventListener('submit', e => {
e.preventDefault();
const text = input.value.trim();
if (!text) return alert('Merci d’entrer une tâche');
addTask(text);
input.value = 'Merci d’entrer une tâche';
});
function addTask(text) {
const li = document.createElement('li');
const span = document.createElement('span');
span.textContent = text;
const doneBtn = document.createElement('button');
doneBtn.textContent = '✓';
const delBtn = document.createElement('button');
delBtn.textContent = '✕';
doneBtn.onclick = () => li.classList.toggle('completed');
delBtn.onclick = () => list.removeChild(li);
li.appendChild(span);
li.append(doneBtn, delBtn);
list.appendChild(li);
}