-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathtodo.py
73 lines (71 loc) · 2.12 KB
/
todo.py
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple To-Do List</title>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
max-width: 400px;
margin: 0 auto;
}
h1 {
text-align: center;
}
#task-input {
width: 100%;
padding: 10px;
margin-bottom: 10px;
}
#task-list {
list-style: none;
padding: 0;
}
.task-item {
display: flex;
justify-content: space-between;
align-items: center;
border: 1px solid #ddd;
padding: 10px;
margin: 5px 0;
background-color: #f9f9f9;
}
.task-remove {
color: red;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<h1>Simple To-Do List</h1>
<input type="text" id="task-input" placeholder="Add a new task">
<ul id="task-list"></ul>
</div>
<script>
const taskInput = document.getElementById('task-input');
const taskList = document.getElementById('task-list');
// Add a new task
taskInput.addEventListener('keypress', function(event) {
if (event.key === 'Enter' && taskInput.value.trim() !== '') {
const taskText = taskInput.value.trim();
const taskItem = document.createElement('li');
taskItem.className = 'task-item';
taskItem.innerHTML = `
<span>${taskText}</span>
<span class="task-remove">❌</span>
`;
taskList.appendChild(taskItem);
taskInput.value = '';
// Remove the task when the '❌' is clicked
taskItem.querySelector('.task-remove').addEventListener('click', function() {
taskList.removeChild(taskItem);
});
}
});
</script>
</body>
</html>