-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
36 lines (25 loc) · 900 Bytes
/
main.js
File metadata and controls
36 lines (25 loc) · 900 Bytes
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
// getting input element
let filterInput = document.getElementById("filterInput")
// Adding Event Listener
filterInput.addEventListener('keyup',filterNames)
function filterNames() {
// Getting value of input
let filterVal = document.getElementById("filterInput").value.toUpperCase()
// getting (ul) list
let ul = document.getElementById("names")
// getting li's from ul
let li = ul.querySelectorAll('li.collection-item')
// loop through each List item (li)
li.forEach(function(elem, index){
// get the anchor tag (a) from li , elem is = li
let a = elem.getElementsByTagName('a')[0]
// match
if(a.innerHTML.toUpperCase().indexOf(filterVal) > -1) { // "indexOf" returns index if found(which is>0) & if not found returns -1
// match found
elem.style.display = ''
} else {
// match Not found
elem.style.display = 'none'
}
})
}