-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
109 lines (93 loc) · 2.75 KB
/
index.html
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html>
<head>
<title>To-Do List App</title>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
max-width: 400px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
h1 {
text-align: center;
}
input[type="text"] {
width: 100%;
padding: 10px;
margin-bottom: 10px;
}
ul {
list-style-type: none;
padding-left: 0;
}
li {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
background-color: #f9f9f9;
margin-bottom: 5px;
}
li.completed {
text-decoration: line-through;
color:#999999;
}
.delete-btn{
background-color:#ff0000;
color:#ffffff;
border:none;
padding:.5rem .75rem;
cursor:pointer;
font-size:.8rem;
border-radius:.25rem
}
</style>
</head>
<body>
<div class="container">
<h1>To-Do List</h1>
<input type="text" id="taskInput" placeholder="Enter a task">
<ul id="taskList"></ul>
</div>
<script>
// Get the input field and the task list
const taskInput = document.getElementById("taskInput");
const taskList = document.getElementById("taskList");
// Add event listener to the input field
taskInput.addEventListener("keydown", function(event) {
if (event.key === "Enter") {
event.preventDefault();
addTask();
}
});
// Function to add a new task
function addTask() {
const taskText = taskInput.value.trim();
if (taskText !== "") {
const li = document.createElement("li");
li.innerHTML = `
<span>${taskText}</span>
<button class="delete-btn">Delete</button>
`;
// Add event listener to the delete button
const deleteBtn = li.querySelector(".delete-btn");
deleteBtn.addEventListener("click", function() {
li.remove();
});
// Add event listener to mark the task as completed
li.addEventListener("click", function() {
li.classList.toggle("completed");
});
taskList.appendChild(li);
// Clear the input field
taskInput.value = "";
}
}
</script>
</body>
</html>