-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (26 loc) · 767 Bytes
/
app.js
File metadata and controls
32 lines (26 loc) · 767 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
32
let taskId = 0;
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
const data = ev.dataTransfer.getData("text");
const task = document.getElementById(data);
ev.target.closest(".task-list").appendChild(task);
}
function addTask() {
const input = document.getElementById("newTask");
const taskText = input.value.trim();
if (!taskText) return;
const task = document.createElement("div");
task.className = "task";
task.id = `task-${taskId++}`;
task.draggable = true;
task.ondragstart = drag;
task.textContent = taskText;
document.getElementById("todo").appendChild(task);
input.value = "";
}