-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
43 lines (34 loc) · 1.56 KB
/
app.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
// const search = () => {
// const searchbox = document.getElementById("search-item").ariaValueMax.toUpperCase();
// const storeitems = document.getElementById("product-list");
// const product = document.querySelectorAll(".product");
// const pname = document.getElementsByTagName("h2");
// for(let i=0; i < pname.length(); i++){
// let match = product[i].getElementsByTagName("h2")[0];
// if(match){
// let textvalue = match.textContent || match.innerHTML;
// if(textvalue.toUpperCase().indexOf(searchbox) > -1){
// product[i].style.display = "";
// }else{
// product[i].style.display = "none";
// }
// }
// }
// }
let searchForm = document.getElementById('search-item');
let searchResultList = document.querySelectorAll('.product');
let result = document.getElementById('product-list');
let searchValue = result.getElementsByTagName("h2");
searchForm.addEventListener("keyup", function(){
for(let i=0; i< searchValue.length; i++){
console.log(searchForm.value);
let value = searchResultList[i].getElementsByTagName('p')[0];
let filterValue = value.textContent || value.innerHTML;
if(filterValue.toUpperCase().indexOf(searchForm.value.toUpperCase()) > -1){
searchResultList[i].style.display = "";
}
else{
searchResultList[i].style.display="none";
}
}
});