-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
54 lines (45 loc) · 1.38 KB
/
scripts.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
const toDo = document.getElementById('todo');
const submitBtn = document.getElementById('submitBtn');
const tableItem = document.querySelector('table');
submitBtn.addEventListener('click', createTodo);
toDo.addEventListener('keypress', function (event) {
if (event.key === 'Enter') {
event.preventDefault();
submitBtn.click();
}
});
function createTodo() {
tableItem.innerHTML += `
<td class='td'id="createdTodo">
${toDo.value}
</td>
<td>
<input type='checkbox' id="checkbox" onclick="isChecked(event)">
</td>
<td>
<button id="dlt2" type='button'><i id="" class="fa-solid fa-trash" onclick="deleteToDoItem(event)"></i></button>
</td>`;
toDo.value = '';
}
function deleteToDoItem(e) {
const tshcan = e.target;
const button = tshcan.parentElement;
const parentTD = button.parentElement;
const parentTR = parentTD.parentElement;
const siblingTD = parentTD.previousElementSibling;
const sibChildTD = siblingTD.querySelector('#checkbox');
if (sibChildTD.checked) {
parentTR.remove();
}
}
function isChecked(e) {
const checkbox = e.target;
const parentTR = checkbox.parentElement;
const siblingTD = parentTR.previousElementSibling;
if (checkbox.checked) {
siblingTD.style.textDecoration = 'line-through';
}
else {
siblingTD.style.textDecoration = '';
}
};