forked from codemistic/Web-Development
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
23 lines (19 loc) · 769 Bytes
/
script.js
File metadata and controls
23 lines (19 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
document.querySelector("#eraser").addEventListener("click", () => {
document.querySelector("#groceryItems").textContent = "";
})
document.querySelector("#userInput").addEventListener("keydown", (event) => {
if (event.key == "Enter")
addItem();
});
addItem = () => {
const item = document.createElement("h2")
item.textContent = "- " + document.querySelector("#userInput").value;
item.addEventListener("click", () => {
if (item.style.textDecoration != "line-through")
item.style.textDecoration = "line-through";
else
item.style.textDecoration = "none";
})
document.querySelector("#groceryItems").appendChild(item);
document.querySelector("#userInput").value = "";
}