Skip to content

Instantly share code, notes, and snippets.

@toledox82
Last active December 22, 2015 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toledox82/6443241 to your computer and use it in GitHub Desktop.
Save toledox82/6443241 to your computer and use it in GitHub Desktop.
// Live Search
function liveSearch() {
// Retrieve the input field text and reset the count to zero
var filter = $('#search-filter').val(), count = 0;
// Loop through the comment list
$(".main-list li").each(function(){
// If the list item does not contain the text phrase fade it out
if ($(this).text().search(new RegExp(filter, "i")) < 0) {
$(this).hide();
// Show the list item if the phrase matches and increase the count by 1
} else {
$(this).show();
count++;
}
});
$("#filter-count").text(count + " domínios");
}
$("#search form").submit(function(){
liveSearch();
return false;
});
$("#search form").keyup(function(){
setTimeout(function(){
liveSearch()
},1000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment