-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
25 lines (22 loc) · 779 Bytes
/
script.js
File metadata and controls
25 lines (22 loc) · 779 Bytes
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
$(document).ready(function () {
// Add task
$('#addBtn').click(function () {
const taskText = $('#taskInput').val().trim();
if (taskText !== '') {
const newTask = $(`<li>${taskText} <span class="remove-btn">✖</span></li>`);
$('#taskList').append(newTask.hide().fadeIn());
$('#taskInput').val('');
}
});
// Toggle task completion using event delegation
$('#taskList').on('click', 'li', function () {
$(this).toggleClass('completed');
});
// Remove task using event delegation
$('#taskList').on('click', '.remove-btn', function (e) {
e.stopPropagation(); // Prevent triggering the li click
$(this).parent().fadeOut(function () {
$(this).remove();
});
});
});