Skip to content

Commit 6d0bfad

Browse files
Merge pull request #126 from pradipchaudhary/project95
init app [project95]
2 parents 0778de8 + fe04928 commit 6d0bfad

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<link rel="stylesheet" href="styles.css" />
7+
<title>Reducing DOM Manipulations App</title>
8+
</head>
9+
<body>
10+
<div class="container">
11+
<h1>Reducing DOM Manipulations App</h1>
12+
<ul id="listContainer">
13+
<!-- List items will be dynamically added here -->
14+
</ul>
15+
<button id="addItemBtn">Add Item</button>
16+
</div>
17+
18+
<script src="script.js"></script>
19+
</body>
20+
</html>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Function to add a new list item
2+
function addItem() {
3+
const listContainer = document.getElementById("listContainer");
4+
const newItem = document.createElement("li");
5+
newItem.textContent = `Item ${listContainer.childElementCount + 1}`;
6+
7+
// Add event listener to the new item
8+
newItem.addEventListener("click", handleItemClick);
9+
10+
// Append the new item to the list container
11+
listContainer.appendChild(newItem);
12+
}
13+
14+
// Function to handle item click (event delegation)
15+
function handleItemClick(event) {
16+
alert(`You clicked on: ${event.target.textContent}`);
17+
}
18+
19+
// Add event listener to the "Add Item" button
20+
document.getElementById("addItemBtn").addEventListener("click", addItem);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
body {
2+
font-family: Arial, sans-serif;
3+
display: flex;
4+
align-items: center;
5+
justify-content: center;
6+
height: 100vh;
7+
margin: 0;
8+
}
9+
10+
.container {
11+
text-align: center;
12+
}
13+
14+
button {
15+
padding: 5px 10px;
16+
}

0 commit comments

Comments
 (0)