-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
72 lines (50 loc) · 2.21 KB
/
script.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
window.addEventListener("load", () => {
const todotaskform = document.querySelector("#todotaskform");
const todotask = document.querySelector("#todotask");
const tasks = document.querySelector(".tasks")
todotaskform.addEventListener("submit", (e) => {
e.preventDefault();
// console.log(todotask.value);
// console.log("hii")
const taskvalue = todotask.value;
if (taskvalue === "") {
alert("write something in To-Do")
} else {
const tasksdiv = document.createElement("div");
tasksdiv.classList.add("task")
const content = document.createElement("div");
content.classList.add("content")
tasksdiv.append(content);
const inputfield = document.createElement("input");
inputfield.type = "text";
inputfield.value = taskvalue;
inputfield.setAttribute("readonly", "readonly");
content.append(inputfield);
const editdeletetask = document.createElement("div");
editdeletetask.classList.add("editdelete")
const edit = document.createElement("i");
edit.classList.add("fa-pencil");
const deletetask = document.createElement("i");
deletetask.classList.add("fa-trash");
editdeletetask.append(edit);
editdeletetask.append(deletetask);
content.append(editdeletetask);
edit.addEventListener("click", () => {
if (edit.classList.contains("fa-pencil")) {
edit.classList.replace("fa-pencil", "fa-trash");
inputfield.removeAttribute("readonly");
inputfield.focus();
} else {
edit.classList.replace("fa-trash", "fa-pencil");
inputfield.setAttribute("readonly", "readonly");
}
})
deletetask.addEventListener("click", () => {
tasksdiv.remove();
})
tasks.append(tasksdiv);
// tasksdiv.append(content);
todotask.value = "";
}
})
})