Hide table row based on content of table cell
Posted
by
timkl
on Stack Overflow
See other posts from Stack Overflow
or by timkl
Published on 2011-02-20T22:21:22Z
Indexed on
2011/02/20
23:25 UTC
Read the original article
Hit count: 291
I want to make some jQuery that shows some table rows and hides others based on the content of the first table cell in each row.
When I click a list item I want jQuery to check if the first letter of the item matches the first letter in any table cell in my markup, if so the parent table row should be shown and other rows should be hidden.
This is my markup:
<ul>
<li>A</li>
<li>B</li>
<li>G</li>
</ul>
<table>
<tr>
<td>Alpha1</td>
<td>Some content</td>
</tr>
<tr>
<td>Alpha2</td>
<td>Some content</td>
</tr>
<tr>
<td>Alpha3</td>
<td>Some content</td>
</tr>
<tr>
<td>Beta1</td>
<td>Some content</td>
</tr>
<tr>
<td>Beta2</td>
<td>Some content</td>
</tr>
<tr>
<td>Beta3</td>
<td>Some content</td>
</tr>
<tr>
<td>Gamma1</td>
<td>Some content</td>
</tr>
<tr>
<td>Gamma2</td>
<td>Some content</td>
</tr>
<tr>
<td>Gamma3</td>
<td>Some content</td>
</tr>
</table>
So if I press "A" this is what is rendered in the browser:
<ul>
<li>A</li>
<li>B</li>
<li>G</li>
</ul>
<table>
<tr>
<td>Alpha1</td>
<td>Some content</td>
</tr>
<tr>
<td>Alpha2</td>
<td>Some content</td>
</tr>
<tr>
<td>Alpha3</td>
<td>Some content</td>
</tr>
</table>
I'm really new to jQuery so any hint on how to go about a problem like this would be appreciated :)
© Stack Overflow or respective owner