Skip to content

Commit 31eecb7

Browse files
committed
added search functionality
1 parent e2b41ae commit 31eecb7

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</li>
4949
</ul>
5050
<form class="form-inline my-2 my-lg-0">
51-
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
51+
<input class="form-control mr-sm-2 note-search" type="search" placeholder="Search" onkeyup="note_search()" aria-label="Search">
5252
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
5353
</form>
5454
</div>

js/script.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function add_note(title_el,data_el)
116116
main_container = document.getElementById('nt');
117117
main_container.appendChild(note_card);
118118
html = `
119-
<div class="card text-white bg-dark mx-1 mb-3" id="${notes_count+1}" style=" max-width: 18rem; min-width: 18rem;">
119+
<div class="card text-white bg-dark mx-1 mb-3" id="${notes_count+1}" style=" max-width: 18rem; min-width: 18rem;">
120120
<div class="card-header row container-fluid justify-content-between" style="margin: 0px !important">
121121
Note: ${notes_count+1} <i" onclick="notedelete(${notes_count+1},'${title_el}')"style="padding: 3px 0 0 0; cursor:pointer;" class="fa fa-trash" aria-hidden="true"></i>
122122
@@ -186,17 +186,19 @@ function saved_notes_display()
186186
for(var title in note)
187187
{
188188
if(all_dom_notes_title.length)
189-
all_dom_notes_title.forEach(function note_exist_in_dom_checker(domtitle,ind)
190-
{
191-
192-
193-
if(title!=domtitle)
189+
{ all_dom_notes_title.forEach(function note_exist_in_dom_checker (domtitle,ind)
194190
{
195-
data = note[title];
196-
add_note(title,data);
197-
}
191+
198192

199-
});
193+
if(title!=domtitle)
194+
{
195+
data = note[title];
196+
add_note(title,data);
197+
198+
}
199+
200+
});
201+
}
200202
else{
201203

202204
data = note[title];
@@ -229,6 +231,28 @@ function alert_shower(type,msg)
229231
</button>
230232
</div>
231233
`
234+
}
235+
////////////////////////////////search function///////////////////////////////
236+
237+
function note_search(e)
238+
{
239+
input = document.getElementsByClassName('note-search')[0].value.toLowerCase();
240+
cards = document.getElementsByClassName('card-title');
241+
242+
for(i=0;i<cards.length;i++)
243+
{
244+
if(cards[i].innerHTML.toLowerCase().indexOf(input) > -1)
245+
{
246+
cards[i].parentNode.parentNode.style.display="";
247+
}
248+
else
249+
{
250+
cards[i].parentNode.parentNode.style.display="none";
251+
}
252+
253+
}
254+
255+
232256
}
233257
//////////////////////////////////////text transition using anime.js/////////////////////////////////////////
234258

0 commit comments

Comments
 (0)