-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadAllTodo.js
51 lines (42 loc) · 1.61 KB
/
loadAllTodo.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
46
47
48
49
50
51
function loadTodos(id, item) {
const itemContainer = document.createElement("LI");
itemContainer.setAttribute("id", `todo-${id}`);
itemContainer.setAttribute("class", `list-item`);
// reload todo container label
const itemLabel = document.createElement("LABEL");
itemLabel.setAttribute("for", `${id}`);
// reloadtodo task as label title.
itemLabel.setAttribute("title", item);
// reload todo container checkbox
const checkBox = document.createElement("INPUT");
checkBox.setAttribute(
"aria-label",
`check the checkbox to mark this task as completed`
);
checkBox.type = "checkbox";
checkBox.setAttribute("id", `${id}`);
checkBox.setAttribute("class", "list_item");
if (id.includes("completed")) {
checkBox.checked = true;
}
// Add checkbox to the label before the text
itemLabel.appendChild(checkBox);
itemLabel.appendChild(document.createTextNode(`${item}`));
// reload todo container delete button.
const deleteButton = document.createElement("BUTTON");
deleteButton.type = "button";
deleteButton.setAttribute("class", "deleteButton");
deleteButton.setAttribute("id", `${id}`);
deleteButton.setAttribute("aria-label", "delete task");
deleteButton.setAttribute("style", "{color:#c90;}");
// reload logo to delete button using span.
const deleteSpan = document.createElement("span");
deleteSpan.classList.add("far", "fa-trash-alt");
deleteButton.appendChild(deleteSpan);
// reload label, delete button and checkbox to todo container.
itemContainer.appendChild(itemLabel);
itemContainer.appendChild(deleteButton);
// todoList.appendChild(itemContainer);
return itemContainer;
}
export default loadTodos;