I am looking to implement a live search feature using jQuery. Below is the code snippet I have written:
$("#searchInput").on("keyup", function () {
var searchTerm = $("#searchInput").val();
$('li:contains("' + searchTerm + '")').show().siblings(':not(li:contains("' + searchTerm + '"))').hide();
});
The code successfully shows the <li>
elements containing the searched text, but the second part - hiding the rest of the items - does not work as expected.
Is there a way to hide <li>
elements when searching for unrelated words?