-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (34 loc) · 1.18 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
let saveTask=[]
const inputTask=document.getElementById("input-task")
let inputBtn=document.getElementById("input-btn")
const lisT=document.getElementById("list")
inputBtn.addEventListener("click",function(){
if (inputTask.value === '') {
alert("Please enter a task")
}
else{
saveTask.push(inputTask.value)
renderTask()
inputTask.value = ""
}
})
function renderTask(){
//let listItems= ""
const li =document.createElement("li")
const closebtn=document.createElement("Button")
closebtn.className="close"
closebtn.innerHTML="✓"
//add a list item
for(let i=0;i<saveTask.length;i++)
{
// listItems+= "<li>" + saveTask[i] + "</li> "
li.textContent=saveTask[i]
li.appendChild(closebtn) //add button to list
lisT.appendChild(li)
}
//delete the complete list on button click
closebtn.addEventListener("click",function(){
li.style.display="none"
})
//lisT.innerHTML=listItems
}