-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
28 lines (22 loc) · 837 Bytes
/
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
const addInput = document.getElementById("add_input");
const itemsList = document.getElementById("items_list");
function removeItem(e) {
const removeParent = e.parentNode;
removeParent.remove()
}
addInput.addEventListener("keyup", e => {
const inputValue = addInput.value;
if (e.keyCode === 13 && inputValue.length > 0) {
const newItem = document.createElement("li");
newItem.classList.add("items");
newItem.innerText = inputValue;
const delBtn = document.createElement("button");
delBtn.classList.add("del_btn");
delBtn.setAttribute("key", inputValue);
delBtn.innerText = "Remove";
delBtn.setAttribute("onClick", "removeItem(this)");
newItem.appendChild(delBtn);
itemsList.appendChild(newItem);
addInput.value = "";
}
})