-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (34 loc) · 1.04 KB
/
index.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
btn = document.querySelector('#btn');
list = document.querySelector('.ul-list');
input = document.querySelector('#input');
input.addEventListener("keypress", function (event) {
if (event.key === "Enter") {
addItem();
}
});
btn.onclick = function () { addItem() };
function addItem() {
if (input.value != '') {
div = document.createElement('div');
li = document.createElement('li');
btn = document.createElement('button');
btn.innerText = 'x';
li.innerText = input.value;
li.classList.add('list-item');
li.setAttribute('onclick', "strike(this)");
btn.setAttribute('type', 'button');
btn.setAttribute('class', 'del-btn');
btn.setAttribute('onclick', 'deleteItem(this)');
div.append(li);
div.append(btn);
list.append(div);
div.setAttribute('class', 'list-object');
input.value = '';
}
}
function strike(item) {
item.classList.toggle('strike');
}
function deleteItem(btn) {
btn.parentElement.remove()
}