Created
July 13, 2023 05:56
-
-
Save mojzis/d2a4566d4b63163eacd1570ffc680d54 to your computer and use it in GitHub Desktop.
js search in nav
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let searchBox = document.querySelector(".searchBox"); | |
let filterSearch, nav, linkCollection; | |
function processResults() { | |
{#input = document.getElementById("mySearch");#} | |
filterSearch = searchBox.value.toUpperCase(); | |
nav = document.querySelector(".leftnav"); | |
linkCollection = nav.getElementsByClassName("menuitem"); | |
Array.from(linkCollection).forEach(element => { | |
if (element.innerHTML.toUpperCase().indexOf(filterSearch) > -1) { | |
element.style.display = ""; | |
} else { | |
element.style.display = "none"; | |
} | |
}); | |
} | |
searchBox.addEventListener("keyup", () => { | |
processResults(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment