-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (25 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
function createTaskHtml(taskId, task) {
return `<input type="checkbox" onclick="taskDone(${taskId})"><h2 id="task-description-${taskId}" class="task-description">${task}</h2>`
}
/** @returns {number} */
const random = () => Math.floor(Math.random() * 999999999);
function buttonClicked() {
const taskInput = document.querySelector("input#input-task")
/** @type {string} */
const task = taskInput.value;
if(task === "") return;
const taskId = random();
const container = document.querySelector("div#todo-tasks-container");
const taskElement = document.createElement("div");
taskElement.id = `task-container-${taskId}`;
taskElement.className = "task-container";
taskElement.innerHTML = createTaskHtml(taskId, task);
container.appendChild(taskElement);
taskInput.value = ""
}
function taskDone(taskId) {
document.querySelector("div#task-container-"+taskId).classList.add("task-removed");
setTimeout(() => {
document.querySelector("div#task-container-"+taskId).remove();
}, 400);
}