-
Notifications
You must be signed in to change notification settings - Fork 0
/
to-do list.html
107 lines (96 loc) · 2.86 KB
/
to-do list.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
<!-- Code By Tuba-->
<!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;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}
#todo-container {
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
overflow: hidden;
width: 300px;
}
#todo-header {
background-color: #3498db;
color: #fff;
padding: 10px;
text-align: center;
}
#todo-list {
padding: 20px;
}
#task-input {
width: calc(100% - 20px);
padding: 10px;
border: none;
border-bottom: 1px solid #3498db;
outline: none;
}
.task {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
border-bottom: 1px solid #eee;
}
.task span {
flex-grow: 1;
margin-right: 10px;
}
.task button {
background-color: #e74c3c;
color: #fff;
border: none;
padding: 5px 10px;
cursor: pointer;
}
</style>
</head>
<body>
<div id="todo-container">
<div id="todo-header">
<h2>To-Do List</h2>
</div>
<div id="todo-list"></div>
<input type="text" id="task-input" placeholder="Add a new task">
</div>
<script>
const todoList = document.getElementById('todo-list');
const taskInput = document.getElementById('task-input');
taskInput.addEventListener('keyup', function(event) {
if (event.key === 'Enter') {
addTask();
}
});
function addTask() {
const taskText = taskInput.value.trim();
if (taskText !== '') {
const taskElement = document.createElement('div');
taskElement.classList.add('task');
taskElement.innerHTML = `
<span>${taskText}</span>
<button onclick="removeTask(this)">Delete</button>
`;
todoList.appendChild(taskElement);
taskInput.value = '';
}
}
function removeTask(button) {
const taskElement = button.parentNode;
todoList.removeChild(taskElement);
}
</script>
</body>
</html>