-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
44 lines (37 loc) · 1 KB
/
main.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
const list = [
"HTML 5",
"CSS3",
"Angular 2",
"React",
"Node.js",
"Vue.js",
"PHP",
"JavaScript",
"Bootstrap",
];
const output = document.querySelector(".output");
const search = document.querySelector(".filter-input");
window.addEventListener("DOMContentLoaded", loadList);
search.addEventListener("input", filter);
function loadList() {
let temp = `<ul class="list-items">`;
list.forEach((item) => {
temp += `<li class="list-item"> ${item} </li>`;
});
temp += `</ul>`;
output.innerHTML = temp;
}
function filter(e) {
let temp = '';
const result = list.filter(item=> item.toLowerCase().includes(e.target.value.toLowerCase()));
if(result.length>0){
temp = `<ul class="list-items">`;
result.forEach((item) => {
temp += `<li class="list-item"> ${item} </li>`;
});
temp += `</ul>`;
}else{
temp =`<div class="no-item"> No Item Found </div>`;
}
output.innerHTML =temp;
}