-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (21 loc) · 880 Bytes
/
Copy pathscript.js
File metadata and controls
28 lines (21 loc) · 880 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
26
27
28
const taskForm = document.getElementById('taskForm');
const taskList = document.getElementById('taskList');
// Listen for form submission
taskForm.addEventListener('submit', function(e) {
e.preventDefault(); // Prevent page refresh
// Get the value of the input
const taskName = document.getElementById('subject').value.trim();
if(taskName === "") return; // Don't add empty tasks
// Create a new task element
const newTask = document.createElement('h4');
newTask.innerHTML = `${taskName} <button onclick="markDone(this)">DONE</button>`;
// Add the new task to the list
taskList.appendChild(newTask);
// Clear the input field
document.getElementById('subject').value = '';
});
// Function to mark a task as done
function markDone(button) {
const task = button.parentElement;
task.style.textDecoration = "line-through";
}