-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (31 loc) · 940 Bytes
/
Copy pathscript.js
File metadata and controls
44 lines (31 loc) · 940 Bytes
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
//selectors
const input=document.querySelector(".noteInput");
const addBtn=document.querySelector(".addBtn");
const notelist=document.querySelector(".noteList");
//Add button event
addBtn.addEventListener("click", ()=>{
//get input text
const text= input.value.trim();
//trim function removes white spaces from start and end
//empty string case
if(text=== ""){
alert("Can't keep empty");
return;
}
//create new li element
const list= document.createElement("li");
list.textContent=text;
//create delete button
const dltBtn= document.createElement("button");
dltBtn.textContent="DELETE";
dltBtn.classList.add("delete")
//deleteBtn event
dltBtn.addEventListener("click", ()=>{
list.remove();
});
//append elements
list.appendChild(dltBtn);
notelist.appendChild(list);
//Clear input
input.value="";
});