-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
81 lines (75 loc) · 2.01 KB
/
script.js
File metadata and controls
81 lines (75 loc) · 2.01 KB
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
console.log("Pretty-Notes");
display();
let button=document.getElementById("addbutton");
button.addEventListener("click",function(e){
let text=document.getElementById("addtext");
let notes=localStorage.getItem("notes");
if(notes==null){
notesarr=[];
}
else{
notesarr=JSON.parse(notes);
}
notesarr.push(addtext.value);
localStorage.setItem("notes",JSON.stringify(notesarr));
//to clear input
addtext.value="";
console.log(notesarr);
alert("Congrats :) you have saved your notes")
display();
});
function display(){
let notes=localStorage.getItem("notes");
if(notes==null){
notesarr=[];
}
else{
notesarr=JSON.parse(notes);
}
let allnotes="";
notesarr.forEach(function(element,index) {
allnotes+=`
<div class="card">
<h5>Note -${index+1}</h5>
<hr>
<p>${element}</p>
<button onclick="deletelement(this.id)" id="${index}" class="btn bg-red">delete</button>
</div>
`
});
let notessection=document.getElementById("notessec");
if(notesarr!=0){
notessec.innerHTML=allnotes;
}
else{
notessec.innerHTML=`Nothing to show! Please Add notes from Add Your Notes section`;
}
}
function deletelement(id)
{
let notes=localStorage.getItem("notes");
if(notes==null)
{
notesarr=[];
}
else{
notesarr=JSON.parse(notes);
}
notesarr.splice(id,1);
localStorage.setItem("notes",JSON.stringify(notesarr));
display();
};
function search1() {
let input = document.getElementById('searchbar').value
input=input.toLowerCase();
let x = document.getElementsById("notesec");
for (i = 0; i < x.length; i++) {
if (!x[i].innerHTML.toLowerCase().includes(input)) {
x[i].style.display="none";
}
else {
x[i].style.display="list-item";
}
}
display();
};