-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroceryItems.html
More file actions
44 lines (42 loc) · 1.12 KB
/
groceryItems.html
File metadata and controls
44 lines (42 loc) · 1.12 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Grocery List</title>
<link rel="stylesheet" href="style.css">
<style>
.container{
display: block;
}
</style>
</head>
<body>
<div class="container">
<div class="content">
<div>
<label for="item">Item:</label>
<input id="item" name="item" type="text">
</div>
<button id="add">Add Item</button>
<ul class="itemList"></ul>
</div>
</div>
<script>
const item = document.getElementById('item');
const submit = document.getElementById('add');
const myList = document.querySelector('ul');
function addItem(){
let itemName = item.value;
//
let newItem = document.createElement('li');
newItem.innerHTML = `${itemName}`
newItem.addEventListener('click', function(){
newItem.remove();
})
myList.appendChild(newItem);
item.value = "";
}
submit.addEventListener('click', addItem);
</script>
</body>
</html>