Skip to content

Instantly share code, notes, and snippets.

@jamalnasir
Last active October 9, 2017 07:14
Show Gist options
  • Save jamalnasir/24fda6e9e5de4f8c9c628987e18f7c0f to your computer and use it in GitHub Desktop.
Save jamalnasir/24fda6e9e5de4f8c9c628987e18f7c0f to your computer and use it in GitHub Desktop.
Search Table with JS/jQuery
$(function(){
var searchTable = function(valueToSearch) {
var value = '';
if(valueToSearch == ''){
$('#filtered tbody tr').fadeIn('fast');
return;
}
$('#filtered tbody tr').fadeOut('fast');
$('#filtered tbody tr').each(function(){
$(this).children().each(function(){
value = $(this).text();
if(value.toLowerCase().indexOf(valueToSearch) !== -1) $(this).parent().fadeIn('fast');
});
});
};
$('#searchForm input[type=search]').keyup(function(){
searchTable($(this).val());
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment