-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (23 loc) · 812 Bytes
/
Copy pathscript.js
File metadata and controls
28 lines (23 loc) · 812 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
window.addEventListener('load', function () {
const form = document.querySelector('#add-todo-form');
const input = document.querySelector('#input-todo');
const btn = document.querySelector('button');
const toDoList = document.querySelector('.todo-list');
form.addEventListener('submit', function (e) {
e.preventDefault();
});
btn.addEventListener('click', function (e) {
if (input.value === '') {
alert('You should enter task');
} else {
let toDo = document.createElement('div');
toDo.classList.add('todo-item');
toDoList.appendChild(toDo);
toDo.innerHTML = input.value;
const toDoAdd = input.value = '';
toDo.addEventListener('click', () => {
toDo.remove()
});
}
});
});