About Lesson
To-Do List Using JQuery:
JavaScript
<!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>
ul {
list-style-type: none;
padding: 0;
}
li {
padding: 5px;
margin: 5px 0;
background-color: #f0f0f0;
cursor: pointer;
}
.completed {
text-decoration: line-through;
color: gray;
}
</style>
</head>
<body>
<input type="text" id="task-input" placeholder="Enter a task" />
<button id="add-task">Add Task</button>
<ul id="task-list"></ul>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script>
$(document).ready(function () {
$("#add-task").click(function () {
const task = $("#task-input").val();
if (task) {
$("#task-list").append(`<li>${task}</li>`);
$("#task-input").val("");
}
});
$(document).on("click", "li", function () {
$(this).toggleClass("completed");
});
$(document).on("dblclick", "li", function () {
$(this).remove();
});
});
</script>
</body>
</html>