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
This will work assuming you only have one select and one table that is stuctured like your example
$(document).ready(function($) {
var rows = $('table tr').each(function() {
var row = $(this);
var columns = row.children('td');
row.data('name-chars', [
columns.eq(0).html()[0].toUpperCase(),
columns.eq(1).html()[0].toUpperCase(),
]);
});
$('select').change(function() {
var char = $(this).val().toUpperCase();
rows.each(function() {
var row = $(this);
var chars_to_match = row.data('name-chars');
if($.inArray(char, chars_to_match) > -1) {
row.show();
}
else {
row.hide();
}
});
});
});