-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
116 lines (86 loc) · 2.84 KB
/
script.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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
console.log("hello everyone")
shownote()
// Adding click funtion so that we can add notes
let addBtn = document.getElementById("addBtn");
addBtn.addEventListener("click", () => {
let addTxt = document.getElementById("addTxt");
let addTit = document.getElementById("addTitle");
let notes = localStorage.getItem("notes");
if (notes == null) {
notesarr = [];
}
else {
notesarr = JSON.parse(notes);
}
// here created a object stored in notesarr in which value of title and adddtext we have passed now and pusshed this ibject in notesarr
let myobj= {
title:addTit.value,
adddtxt:addTxt.value
}
notesarr.push(myobj);
localStorage.setItem("notes", JSON.stringify(notesarr));
addTxt.value = "";
addTit.value="";
console.log(notesarr)
shownote();
})
// this is te show fucnt which will run after we click on creating note
function shownote(element) {
let notes = localStorage.getItem("notes");
if (notes == null) {
notesarr = [];
}
else {
notesarr = JSON.parse(notes);
}
let html = "";
notesarr.forEach(function (element, index) {
html +=
`
<div class="noteCard my-2 mx-2 card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title" id="h55">${element.title}</h5>
<p class="card-text">${element.adddtxt}</p>
<button id="${index}" onclick="delnote(this.id)" class="btn btn-primary" >Delete Node</button>
</div>
</div>
`
});
let noteelem = document.getElementById("notes")
if (notesarr.length != 0) {
noteelem.innerHTML = html;
}
else {
// console.log("else is not workin")
noteelem.innerHTML = "There is no Notes Yet , Use above section to create."
}
}
function delnote(index) {
let notes = localStorage.getItem("notes");
console.log("im del this note", index)
if (notes == null) {
notesarr = [];
}
else {
notesarr = JSON.parse(notes);
}
notesarr.splice(index, 1);
localStorage.setItem("notes", JSON.stringify(notesarr));
shownote();
console.log(`u have clicked on this index ${index} and u r del this note`)
}
let searchb = document.getElementById("searchbox");
searchb.addEventListener("input", function () {
let inputval = searchb.value.toLowerCase();
// console.log("input event is firing",inputval)
let cards = document.getElementsByClassName("noteCard");
Array.from(cards).forEach(function (element) {
let cardtxt = element.getElementsByTagName("p")[0].innerText;
if (cardtxt.includes(inputval)) {
element.style.display = "block";
}
else {
element.style.display = "none";
}
});
});