-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path15.html
More file actions
39 lines (35 loc) · 1.17 KB
/
Copy path15.html
File metadata and controls
39 lines (35 loc) · 1.17 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TO-DO List</title>
</head>
<body>
<h1>To-Do List</h1>
<input type="text" id="newTask" placeholder="Enter a new task">
<button id="addTask">Add Task</button>
<ul id="taskList"></ul>
<script>
const newTaskInput = document.getElementById('newTask');
const addTaskButton = document.getElementById('addTask');
const taskList = document.getElementById('taskList');
addTaskButton.addEventListener('click', addTask);
taskList.addEventListener('click', removeTask);
function addTask() {
const taskText = newTaskInput.value;
if (taskText.trim() !== '') {
const taskItem = document.createElement('li');
taskItem.textContent = taskText;
taskList.appendChild(taskItem);
newTaskInput.value = '';
}
}
function removeTask(event) {
if (event.target.tagName === 'LI') {
event.target.remove();
}
}
</script>
</body>
</html>