-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
38 lines (36 loc) · 1.14 KB
/
Copy pathindex.html
File metadata and controls
38 lines (36 loc) · 1.14 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>To-Do List</title>
<style>
body { font-family: Arial, sans-serif; }
#todo-list { list-style-type: none; padding: 0; }
#todo-list li { padding: 8px; border: 1px solid #ddd; margin-top: -1px; }
</style>
</head>
<body>
<h1>To-Do List</h1>
<input type="text" id="task" placeholder="Enter a new task">
<button onclick="addTask()">Add Task</button>
<ul id="todo-list"></ul>
<script>
function addTask() {
var taskInput = document.getElementById("task");
var task = taskInput.value;
if (task === "") {
alert("Please enter a task.");
return;
}
var li = document.createElement("li");
li.textContent = task;
li.onclick = function() {
this.parentElement.removeChild(this);
};
document.getElementById("todo-list").appendChild(li);
taskInput.value = "";
}
</script>
</body>
</html>