-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
45 lines (42 loc) · 1.06 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
var c=0;
function addlistitem(){
var s = document.getElementById("new").value;
if(s.length===0)
return false;
var td1 = document.createElement("td");
var tr = document.createElement("tr");
var table = document.getElementById("table");
table.appendChild(tr);
td1.innerHTML=s;
tr.appendChild(td1);
td1.bgColor="tomato";
document.getElementById("new").value = "";
var td2 = document.createElement("td");
var dlt = document.createElement("button");
dlt.innerHTML="X";
td2.appendChild(dlt);
tr.appendChild(td2);
dlt.onclick=deletelistitem;
td1.onclick=changecolor;
c++;
tr.id=c;
td1.width="90%";
function changecolor(){
if(td1.bgColor=="tomato")
td1.bgColor="lime";
else
td1.bgColor="tomato";
}
function deletelistitem(){
if(confirm("Confirm deletion?")===false)
return false;
var index = parseInt(tr.id);
table.removeChild(table.childNodes[index]);
var i;
for(i=index+1;i<=c;i++)
{
document.getElementById(i).id=i-1;
}
c--;
}
}