-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (34 loc) · 1.03 KB
/
Copy pathscript.js
File metadata and controls
48 lines (34 loc) · 1.03 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
44
45
46
47
48
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("card",
ev.target.id);
}
function drop(ev, id) {
ev.preventDefault();
const target = document.getElementById(id);
const data =
ev.dataTransfer.getData("card");
const cardId = document.getElementById(data)
target.appendChild(cardId);
ev.dataTransfer.clearData();
}
function addCard(element) {
const text = prompt('Qual é a tarefa?');
if (!text) return;
const cardId = +new Date();
const cardTemplate = `
<li id="${cardId}" class="card"
draggable="true" ondragstart="drag(event)">
<p>${text}</p>
<p class="remove" onclick="removeCard(this)">x</p>
</li>
`
const board =
document.getElementById(element.previousElementSibling.id);
board.innerHTML += cardTemplate;
}
function removeCard (element) {
document.getElementById(element.parentElement.id).remove();
}