summaryrefslogtreecommitdiff
path: root/graphs/js/todoList/todoList.js
blob: 34b2edf6825d76337a145c2bb7d132e794f64e6b (plain)
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
const input = document.getElementById("textBox");
const addBtn = document.getElementById("addButton");
const list = document.getElementById("todoList");

addBtn.addEventListener("click", () => {
    if (input.value === "") {
        return;
    }

    const todo = document.createElement("li");

    todo.classList.add("todoItem");
    const label = document.createElement("span");

    label.innerHTML = input.value;
    input.value = "";
    label.classList.add("todoText");
    todo.appendChild(label);
    const del = document.createElement("button");

    del.innerHTML = "Delete";
    del.addEventListener("click", () => {
        list.removeChild(todo);
    });
    todo.appendChild(del);
    list.appendChild(todo);
});