-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (36 loc) · 1.2 KB
/
script.js
File metadata and controls
44 lines (36 loc) · 1.2 KB
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
const taskInput = document.getElementById('taskInput');
const taskList = document.getElementById('taskList');
// Add a new task to the list
function addTask() {
const taskText = taskInput.value.trim();
if (taskText === '') return;
const li = document.createElement('li');
li.innerHTML = `
<span>${taskText}</span>
<div class="actions">
<button onclick="toggleCompletion(this)">Done</button>
<button onclick="editTask(this)">Edit</button>
<button onclick="deleteTask(this)">Delete</button>
</div>
`;
taskList.appendChild(li);
taskInput.value = '';
}
// Toggle task completion status
function toggleCompletion(button) {
const taskText = button.parentNode.previousElementSibling;
taskText.classList.toggle('completed');
}
// Edit task
function editTask(button) {
const taskText = button.parentNode.previousElementSibling;
const newText = prompt('Edit the task:', taskText.textContent.trim());
if (newText !== null && newText.trim() !== '') {
taskText.textContent = newText.trim();
}
}
// Delete task
function deleteTask(button) {
const li = button.parentNode.parentNode;
taskList.removeChild(li);
}