How can I select tbody’s children and not their descendants? For example, using the following jQuery statement:
alert( $( '.someClass tbody tr' ).length );
will yield a length of 2 using the sample html below:
<div>
<table class='someClass'>
<tbody>
<tr>
<td>
<span>cell 1-1</span>
<table>
<tbody>
<tr class='level-2'>
<td>
<span>cell 1-2</span>
<table>
<tbody>
<tr class='level-3'>
<td><span>cell 1-3</span></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<span>cell 2-1</span>
<table>
<tbody>
<tr class='level-2'>
<td>
<span>cell 2-2</span>
<table>
<tbody>
<tr class='level-3'>
<td><span>cell 2-3</span></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
You can do it like this:
That’s actually a css2 selector, which jQuery nicely implements.