-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
60 lines (46 loc) · 1.9 KB
/
main.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
52
53
54
55
56
57
58
59
60
window.addEventListener('load', () => {
const form = document.querySelector('#input-form');
const input = document.querySelector('.input');
const tasks = document.querySelector('.tasks');
form.addEventListener('submit', (e) => {
e.preventDefault();
if (!input.value) return;
const taskText = input.value;
const divTask = document.createElement('div');
divTask.classList.add('task');
const inputTask = document.createElement('input');
inputTask.classList.add('input-task');
inputTask.type = 'text';
inputTask.value = taskText;
inputTask.setAttribute('readonly', 'readonly');
inputTask.setAttribute('spellcheck', 'false');
const divBtn = document.createElement('div');
divBtn.classList.add('buttons');
const edit = document.createElement('button');
edit.classList.add('edit');
edit.innerText = 'Edit';
const deleteBtn = document.createElement('button');
deleteBtn.classList.add('delete');
deleteBtn.innerText = 'Delete';
tasks.appendChild(divTask);
divTask.appendChild(inputTask);
divTask.appendChild(divBtn);
divBtn.appendChild(edit);
divBtn.appendChild(deleteBtn);
deleteBtn.addEventListener('click', () => {
divTask.remove();
});
edit.addEventListener('click', () => {
if (edit.innerText == 'Edit') {
edit.innerText = 'Save';
edit.classList.add('save')
inputTask.removeAttribute('readonly');
} else {
edit.innerText = 'Edit';
edit.classList.remove('save')
inputTask.setAttribute('readonly', 'readonly');
}
});
input.value = '';
});
});