-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
23 lines (20 loc) · 1.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
Task: Comparing the search query vs. the DOM names
1. Create a conditional that checks if currentName is equal to the user's search query!
2. If our conditional returns true, set the display style on 'allNamesDOMCollection[counter]' to be a block element
3. If our conditional falls into the else, we have no match! So set the display style to 'none'
Helpers: use the methods 'includes' for objective 1
- The includes() method determines whether one string may be found within another string, returning true or false as appropriate.
*/
document.getElementById("searchInput").addEventListener("keyup", function(event) {
let searchQuery = event.target.value.toLowerCase();
let allNamesDOMCollection = document.getElementsByClassName('name');
for (let counter = 0; counter < allNamesDOMCollection.length; counter++) {
const currentName = allNamesDOMCollection[counter].textContent.toLowerCase();
if (currentName.includes(searchQuery)) {
allNamesDOMCollection[counter].style.display = "block";
} else {
allNamesDOMCollection[counter].style.display = "none";
}
}
});