-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble.html
More file actions
38 lines (37 loc) · 1.2 KB
/
Copy pathbubble.html
File metadata and controls
38 lines (37 loc) · 1.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<section id="list-container">
<ul>
<li class="item">item</li>
<li class="item">item</li>
<li class="item">item</li>
<li class="item">item</li>
</ul>
<button id="btn-add-item">Add Item</button>
</section>
<script>
const items = document.getElementsByClassName('item');
for (const item of items) {
item.addEventListener('click', function(event) {
event.target.parentNode.removeChild(event.target);
});
}
document.getElementById('btn-add-item').addEventListener('click', function() {
const list = document.querySelector('ul');
const li = document.createElement('li');
li.innerText = 'Add item';
li.classList.add('item');
li.addEventListener('click', function(event) {
event.target.parentNode.removeChild(event.target);
});
list.appendChild(li);
});
</script>
</body>
</html>