-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (35 loc) · 1.31 KB
/
index.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
var table=document.getElementById("table");
var inputText=document.getElementById("inputText");
var addBtn=document.getElementById("addBtn");
addBtn.addEventListener("click",function(){
var newItem = document.createElement("tr");
//item
var itemTd = document.createElement("td");
var newItemText=document.createTextNode(inputText.value);
itemTd.appendChild(newItemText);
newItem.appendChild(itemTd);
//editBtn
var editBtnTd = document.createElement("td");
var editBtn = document.createElement("button");
editBtn.innerHTML="Edit";
editBtn.id="edit";
editBtn.addEventListener("click",function(){
var replacedItemText=document.createTextNode(inputText.value);
itemTd.replaceChild(replacedItemText,newItemText);
})
editBtnTd.appendChild(editBtn);
newItem.appendChild(editBtnTd);
//removeBtn
var removeBtnTd = document.createElement("td");
var removeBtn = document.createElement("button");
removeBtn.id="del";
removeBtn.addEventListener("click",function(){
table.removeChild(newItem);
});
removeBtn.innerHTML="Remove";
removeBtnTd.appendChild(removeBtn);
newItem.appendChild(removeBtnTd);
//append to table
table.appendChild(newItem);
inputText.value="";
});