BLOG/static/scripts/search.js

20 lines
563 B
JavaScript
Raw Permalink Normal View History

2024-10-09 21:48:33 +02:00
function searcher(){
let bar = document.getElementById("search");
let filter = bar.value.toUpperCase();
let posts = Array.from(document.getElementsByClassName("mb-3"));
let a, b, txtValue;
console.log(posts.length);
console.log(posts)
for (i=0; i < posts.length; i++){
a = posts[i].getElementsByTagName("h2")[0];
b = posts[i].getElementsByTagName("li")[3];
if(a.innerText.toUpperCase().indexOf(filter) > -1 || b.innerText.toUpperCase().indexOf(filter) > -1){
posts[i].style.display = "";
}
else {
posts[i].style.display = "none";
}
}
}