-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (25 loc) · 773 Bytes
/
app.js
File metadata and controls
31 lines (25 loc) · 773 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
29
30
31
function addTask() {
let taskInput = document.getElementById("input");
let ul = document.getElementById("ul");
let taskText = taskInput.value;
let li = document.createElement("p");
li.innerHTML = `
<span>${taskText}</span>
<button onclick="editTask(this)">Edit</button>
<button onclick="deleteTask(this)">Delete</button>
`;
ul.appendChild(li);
taskInput.value = "";
}
function editTask(button) {
const li = button.parentElement;
const taskText = li.querySelector("span").innerText;
const newText = prompt("Edit task:", taskText);
if (newText !== null) {
li.querySelector("span").innerText = newText;
}
}
function deleteTask(button) {
const li = button.parentElement;
li.remove();
}