-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathTo-Do List with Priorities
103 lines (103 loc) · 2.58 KB
/
To-Do List with Priorities
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
HTML:
<!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 with Priorities</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="todo-container">
<h1>To-Do List</h1>
<form id="todoForm">
<input type="text" id="taskInput" placeholder="Enter a new task" required>
<select id="prioritySelect" required>
<option value="high">High</option>
<option value="medium">Medium</option>
<option value="low">Low</option>
</select>
<button type="submit">Add Task</button>
</form>
<ul id="taskList"></ul>
</div>
<script src="script.js"></script>
</body>
</html>
CSS:
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.todo-container {
text-align: center;
background-color: #f0f0f0;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 300px;
}
form {
display: flex;
flex-direction: column;
gap: 10px;
}
input, select, button {
padding: 10px;
font-size: 16px;
}
ul {
list-style-type: none;
padding: 0;
}
li {
padding: 10px;
margin: 5px 0;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
display: flex;
justify-content: space-between;
}
li.high {
border-left: 5px solid red;
}
li.medium {
border-left: 5px solid orange;
}
li.low {
border-left: 5px solid green;
}
button.remove {
background: none;
border: none;
color: red;
cursor: pointer;
font-size: 16px;
}
JavaScript:
document.getElementById('todoForm').addEventListener('submit', function(event) {
event.preventDefault();
const taskInput = document.getElementById('taskInput');
const prioritySelect = document.getElementById('prioritySelect');
const taskText = taskInput.value;
const priority = prioritySelect.value;
if (taskText === '') return;
const li = document.createElement('li');
li.textContent = taskText;
li.classList.add(priority);
const removeButton = document.createElement('button');
removeButton.textContent = 'Remove';
removeButton.classList.add('remove');
removeButton.addEventListener('click', function() {
li.remove();
});
li.appendChild(removeButton);
document.getElementById('taskList').appendChild(li);
taskInput.value = '';
prioritySelect.value = 'medium';
});