-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.html
87 lines (71 loc) · 1.83 KB
/
code.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
<!DOCTYPE html>
<html>
<head>
<title>Dynamic To-Do List</title>
<style>
body {
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
background-color: #b2e9f65c;
}
.container {
max-width: 400px;
margin: 20px auto;
background-color: #69c0d854;
padding: 20px;
box-shadow: 0 0 5px rgba(46, 104, 115, 0.349);
border-radius: 5px;
}
h1 {
text-align: center;
}
.task-item {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.task-item label {
flex-grow: 1;
margin-left: 10px;
}
.completed label {
text-decoration: line-through;
color: #ffffff;
}
</style>
</head>
<body>
<div class="container">
<h1>Dynamic To-Do List</h1>
<div>
<input type="text" id="taskInput" placeholder="Enter a task">
<button onclick="addTask()">Add Task</button>
</div>
<ul id="taskList"></ul>
</div>
<script>
function addTask() {
var taskInput = document.getElementById("taskInput");
var taskList = document.getElementById("taskList");
var taskText = taskInput.value.trim();
if (taskText === "") {
return;
}
var newTask = document.createElement("li");
newTask.className = "task-item";
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.onclick = toggleTask;
var taskLabel = document.createElement("label");
taskLabel.textContent = taskText;
newTask.appendChild(checkbox);
newTask.appendChild(taskLabel);
taskList.appendChild(newTask);
taskInput.value = "";
}
function toggleTask() {
var taskLabel = this.nextSibling;
taskLabel.classList.toggle("completed");
}
</script>
</body>
</html>