-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (24 loc) · 1.04 KB
/
script.js
File metadata and controls
31 lines (24 loc) · 1.04 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
document.addEventListener('DOMContentLoaded', function() {
const taskForm = document.getElementById('taskForm');
const taskInput = document.getElementById('taskInput');
const taskList = document.getElementById('taskList');
taskForm.addEventListener('submit', function(event){
event.preventDefault();
const taskText = taskInput.value.trim();
if(taskText !== '') {
const listItem = document.createElement('li');
listItem.className = 'taskItem';
const taskTextSpan = document.createElement('span');
taskTextSpan.textContent = taskText;
const removeButton = document.createElement('button');
removeButton.textContent = 'Remove';
removeButton.addEventListener('click', function(){
taskList.removeChild(listItem);
})
listItem.appendChild(taskTextSpan);
listItem.appendChild(removeButton);
taskList.appendChild(listItem);
taskInput.value = '';
}
});
});