-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
56 lines (50 loc) · 1.96 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ToDo List</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<style>
.completed {
text-decoration: line-through;
}
</style>
</head>
<body class="bg-dark">
<div class="container">
<h2 class="text-success text-center">My To-do List</h2>
<img src="1.jpeg" class="d-block w-100" alt="ToDo list image">
<div class="form-group d-grid gap-2 d-md-flex my-2 ">
<input type="text" id="taskInput" class="form-control" placeholder="Enter task">
<button id="addTask" class="btn btn-success">Add</button>
</div>
<ul id="taskList" class="list-group">
</ul>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
$("#addTask").on("click", function () {
const taskText = $("#taskInput").val();
if (taskText.trim() !== "") {
const taskItem = `
<li class="list-group-item">
<div class="form-check form-switch">
<input class="form-check-input task-checkbox" type="checkbox">
${taskText}
<button class="btn btn-danger btn-sm float-right delete">Delete</button>
</div>
</li>`;
$("#taskList").append(taskItem);
$("#taskInput").val("");
}
});
$("#taskList").on("click", ".delete", function () {
$(this).closest('li').remove();
});
$("#taskList").on("change", ".task-checkbox", function () {
$(this).closest('li').toggleClass("completed");
});
</script>
</body>
</html>