Alex Hansen Alex Hansen -4 years ago 44
jQuery Question

Checking to see if an element belongs to a parent HTML tag

I have a table of the format:

<table>
<thead>
<tr>
<td>
some header stuff
</td>
<td>
header 2
</td>
</tr>
</thead>
<tfoot>
<tr>
<td>
some info I don't want or need
</td>
<td>
other info I don't want or need
</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>
real info
</td>
<td>
real info
</td>
</tr>
</tbody>
</table>


I would like to iterate through all table rows but ignore the tfoot. When I get all elements of tag "tr", I find myself hoping for some function like this.containsParentTag. How would one accomplish this? I cannot find this use case in the JQuery docs for $().filter().

Answer Source

The following should work. You can chain selectors with comma

$('thead tr, tbody tr')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download