I have the following code to do a real-time search with jQuery, searching for values inside a table:
$(document).ready(function () {
$(".nada").hide();
var $rows = $('.linhas');
$('#search').keyup(function () {
var val = '^(?=.*\b' + $.trim($(this).val()).split(/\s+/).join('\b)(?=.*\b') + ').*$',
reg = RegExp(val, 'i'),
text;
$rows.show().filter(function () {
text = $(this).text().replace(/\s+/g, ' ');
return !reg.test(text);
}).hide().filter(function () {
$(".nada").show();
});
});
});
But there is a problem: even if I only return a value equal to what is typed, it falls in hide()
and shows $('.nada').show()
.
How can I fix this?