Reputation: 43
I'm creating a prototype website with a table. I just want to know how can I filter the table contents? Example I have two buttons which are 'writers' and 'illustrators' and when I click the button for writer, I just want the table to just show the writers.
Is it possible to filter it using the table row id class?
Like:
<table>
<tr class="writer">
<td>John Doe </td>
<td>Jan 01, 1980</td>
<td>[email protected]</td>
</tr>
<tr clas="illustrator">
<td>Jane Doe </td>
<td>Sept 01, 1980</td>
<td>[email protected]</td>
</tr>
<tr class="illustrator">
<td>Mel Smith </td>
<td>Aug 01, 1980</td>
<td>[email protected]</td>
</tr>
<tr class="writer">
<td>Harry Smith </td>
<td>Dec 01, 1980</td>
<td>[email protected]</td>
</tr>
</table>
Or are there any easy way to do it?
Upvotes: 0
Views: 46
Reputation: 388316
Are you looking for something like
jQuery(function () {
$('#illustrator').click(function () {
$('table tr.writer').hide();
$('table tr.illustrator').show();
})
$('#writer').click(function () {
$('table tr.writer').show();
$('table tr.illustrator').hide();
})
})
Demo: Fiddle
Upvotes: 1