Search Bar Without Entry
Search Bar With Entry
In the images above, I have a search bar that allows for input, and filters once an input has been given. However, I want to go one step further and add a highlight to the text when an input has been made. In this example, for picture 2, I would want text highlighted for those selected. This is my current code below.
function myFunction() {
// Declare variables
var input, filter, ul, li, a, i, txtValue;
input = document.getElementById('myInput');
filter = input.value.toUpperCase();
ul = document.getElementById("myUL");
li = ul.getElementsByTagName('li');
// Loop through all list items, and hide those who don't match the search query
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName("a")[0];
txtValue = a.textContent || a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
li[i].style.color = 'green';
} else {
li[i].style.display = "none";
}
}