-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
87 lines (52 loc) · 1.87 KB
/
app.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// TODO APP //Muhammad wasi
var list = document.getElementById('list');
function addTodo(){
var todo_item = document.getElementById("todo-item");
//create li tag with text node
var li = document.createElement('li');
var li_text = document.createTextNode(todo_item.value);
li.appendChild(li_text);
//create delete button
var del_btn = document.createElement('button');
var del_text = document.createTextNode("REMOVE");
del_btn.setAttribute("class",'delete');
del_btn.setAttribute("onclick","deleteItem(this)")
del_btn.append(del_text); ////
//create edit button//
var edit_btn = document.createElement("button");
var edit_text = document.createTextNode("EDIT");
edit_btn.setAttribute("class",'edit');
edit_btn.setAttribute("onclick",'editItem(this)');
edit_btn.appendChild(edit_text);
li.appendChild(edit_btn)
li.appendChild(del_btn)
list.appendChild(li);
console.log(li);
todo_item.value = ''; //blank box
}
//Enter button function
var input = document.getElementById("todo-item");
// Execute a function when the user releases a key on the keyboard
input.addEventListener("keyup", function(enter) {
// Number 13 is the "Enter" key on the keyboard
if (enter.keyCode === 13) {
// Cancel the default action, if needed
enter.preventDefault();
// Trigger the button element with a click
document.getElementById("wasi").click();
}
});//////
//delete function
function deleteItem(a){
a.parentNode.remove()
}
//del all
function delAll(){
list.innerHTML = "";
}
//edit Function
function editItem(b){
var val = prompt("Enter What To Do ", b.parentNode.firstChild.nodeValue)
b.parentNode.firstChild.nodeValue = val;
}
//===== END OF CODE =====//