Last active
October 9, 2017 07:14
-
-
Save jamalnasir/24fda6e9e5de4f8c9c628987e18f7c0f to your computer and use it in GitHub Desktop.
Search Table with JS/jQuery
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
$(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