neo
neo

Reputation: 2471

JQuery: How to select table rows but not the rows of the table inside the cell

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

Answers (1)

wirey00
wirey00

Reputation: 33661

you can use .children()

$('#table1').children('tr')

or child selector

$('#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

Related Questions