-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
45 lines (45 loc) · 1.28 KB
/
code.js
File metadata and controls
45 lines (45 loc) · 1.28 KB
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
window.onload = function () {
document.getElementById("addItem").onclick =
saveItem;
document.getElementById("displayItems").onclick
= displayItems;
};
let allItems = [];
function saveItem() {
let itemTitle = document.getElementById("title").value;
let newTask = new ToDoItem(itemTitle);
allItems.push(newTask);
addItemToPage(itemTitle);
clearTextboxes();
}
function addItemToPage(itemTitle) {
let itemList = document.getElementById("itemList");
let newItem = document.createElement("li");
let textNode = document.createTextNode(itemTitle);
newItem.appendChild(textNode);
itemList.appendChild(newItem);
newItem.setAttribute("draggable", "true");
newItem.onclick = function () {
this.remove();
if (this.getAttribute("class") == null) {
this.setAttribute("class", "itemDone");
}
else {
this.removeAttribute("class");
}
};
}
function clearTextboxes() {
document.getElementById("title").value = "";
document.getElementById("title").focus();
}
function displayItems() {
for (let currItem of allItems) {
alert(currItem.title);
}
}
class ToDoItem {
constructor(title) {
this.title = title;
}
}