I\'m trying to filter a table from an alphabetical input with jQuery.
I have first and last names in two columns of the table, and I\'d like
I came up with this. Pretty similar to what Elzo came up with but it limits it to the first two columns of the table.
$('select').change( function(e) {
var letter = $(this).val();
if (letter === 'ALL') {
$ ('tr').show ();
}
else {
$('tr').each( function(rowIdx,tr) {
$(this).hide().find('td').each( function(idx, td) {
if( idx === 0 || idx === 1) {
var check = $(this).text();
if (check && check.indexOf(letter) == 0) {
$(tr).show();
}
}
});
});
}
});
It doesn't ignore case and assumes you have one select and the only tr's on the page are the ones you want to filter.
EDIT Added an 'ALL' option to show rows again.