I have a table which is filled dynamically using php. and I wanted to add search functionality to it. after searching similar questions here on stackoverflow I found a JS snippet which I tried.
var $rows = $('#existing tr');
$('#search').keyup(function() {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
$rows.show().filter(function() {
var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(val);
}).hide();
});
jsfiddle link: http://jsfiddle.net/kvkBw/3/
The problem is that when I enter any search term the table itself gets hidden (goes invisible) any help would be appreciated thanks!.
Note that the php code is removed because php is not supported by jsfiddle and also to increase readability
(text.indexOf(val) === -1). A little too clever, I think.