-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathass8.html
More file actions
41 lines (35 loc) · 1.24 KB
/
ass8.html
File metadata and controls
41 lines (35 loc) · 1.24 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
<!DOCTYPE html>
<html>
<head>
<title>DOM</title>
</head>
<body>
<div id="container">
<h1>My List</h1>
<ul id="myList">
<li class="item">Item 1</li>
<li class="item">Item 2</li>
<li class="item">Item 3</li>
</ul>
<button id="addButton">Add Item</button>
</div>
<script>
const addButton=document.getElementById('addButton');
const myList=document.getElementById('myList');
function remove(event){
event.target.remove();
}
const existing=document.querySelectorAll('.item');
existing.forEach(function(item){
item.addEventListener('Click',remove);
});
addButton.addEventListener('click',function(){
const newitem=document.createElement('li');
newitem.textContent='New Item';
newitem.className='item';
newitem.addEventListener('click',remove);
myList.appendChild(newitem);
});
</script>
</body>
</html>