-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.html
118 lines (95 loc) · 3.37 KB
/
filter.html
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
112
113
114
115
116
117
118
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>My Contacts</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.css">
</head>
<body style="background-color:rgb(199, 179, 179);">
<div class="container">
<h1 class="center-align"
style="color:rgb(98, 54, 50);";
>My Contacts</h1>
<input id="filterInput" placeholder="Search names..." type="text">
<ul id="names" class="collection with-header">
<li class="collection-header" style="background-color:rgb(167, 111, 111);">
<h5>A</h5>
</li>
<li class="collection-item">
<a href="#">Abe</a>
</li>
<li class="collection-item">
<a href="#">Adam</a>
</li>
<li class="collection-item">
<a href="#">Alan</a>
</li>
<li class="collection-item">
<a href="#">Anna</a>
</li>
<li class="collection-header" style="background-color:rgb(168, 109, 109);">
<h5>B</h5>
</li>
<li class="collection-item">
<a href="#">Beth</a>
</li>
<li class="collection-item">
<a href="#">Bill</a>
</li>
<li class="collection-item">
<a href="#">Bob</a>
</li>
<li class="collection-item">
<a href="#">Brad</a>
<li class="collection-header" style="background-color:rgb(165, 107, 107);">
<h5>C</h5>
</li>
<li class="collection-item">
<a href="#">Carrie</a>
</li>
<li class="collection-item">
<a href="#">Cathie</a>
</li>
<li class="collection-item">
<a href="#">Courtney</a>
</li>
</li>
</ul>
</div>
</body>
<script>
// Get Input Element
let filterInput = document.getElementById("filterInput");
// Add event listener
filterInput.addEventListener("keyup",filterNames);
function filterNames(){
//Get value of input
let filterValue = document.getElementById("filterInput").value.toUpperCase();
// Get names ul
let ul = document.getElementById("names");
//Get li's from ul
let li = ul.querySelectorAll("li.collection-item");
//Loop through coll-item lis
for(let i = 0; i < li.length;i++){
let a = li[i].getElementsByTagName("a")[0];
// a domethon linki a ( hrefat be nalt i kie pha)
// If matched
if(a.innerHTML.toUpperCase().indexOf(filterValue) > -1){
li[i].style.display = "";
li[i].style.backgroundColor = "honeydew";
// nqs pershtatet paraqite
} else {
li[i].style.display = "none";
// nqs jo mos paraqit krgj
}
}
}
</script>
<style>
li{
color:ho
}
</style>
</html>