Reputation: 2471
So I have a table, and there are tables within the cell too, like this:
<table id='table1'>
<tr>
<td>xyz</td>
<td>
<table><tr></tr></table>
</td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
</table>
How do I use jquery to select those only directly under "table1", but not those under the inside table?
Upvotes: 0
Views: 68
Reputation: 33661
you can use .children()
$('#table1').children('tr')
$('#table1 > tr')
These will select only direct children elements
as @jonathanlonowski stated, it would be safer to use this due to the browsers adding the extra tbody
markup
$('#table1 > tr,#table1 > tbody > tr')
This would also work
$('#table1').find('tr:first').siblings().andSelf()
Upvotes: 4