-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (48 loc) · 1.59 KB
/
script.js
File metadata and controls
65 lines (48 loc) · 1.59 KB
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
61
62
63
64
65
// document.querySelector("#submit").onclick = function(){
// /*var textInput = document.getElementById('text').value;
// var node = document.createElement('li');
// node.appendChild(document.createTextNode(textInput));
// document.querySelector('ul').appendChild(node); */
// }
const itemDB = {
items: [
]
};
const itemsLIst = document.querySelector('.add-list'),
form = document.querySelector('form.add-item'),
addInput = form.querySelector('.adding_input');
form.addEventListener('submit', (event) => {
event.preventDefault();
let newItem = addInput.value;
itemDB.items.push(newItem);
createItemList(itemDB.items, itemsLIst);
}) ;
function createItemList(item, parent) {
parent.innerHTML = "";
item.forEach((itm, i) => {
parent.innerHTML += `
<li class="add-item">
<input type="checkbox" name="check" class = "checkBoxEnabled">${i + 1}: <span>${itm}</span>
<div class="delete">
<img src="img/trash.png" alt="trash" class = "trash">
</div>
</li>
`;
});
document.querySelectorAll('.delete').forEach((btn, i) => {
btn.addEventListener('click', () => {
btn.parentElement.remove();
itemDB.items.splice(i, 1);
createItemList(item, parent)
});
});
};
const checkbox = document.getElementById('myCheckbox')
checkbox.addEventListener('change', (event) => {
if (event.currentTarget.checked) {
alert('checked');
} else {
alert('not checked');
}
})
createItemList(itemDB.items, itemsLIst);