Get all parent elements

Asked

Viewed 168 times

3

I’m in a situation where I have a table that doesn’t have class. Staying like this:

<table>
   <tr> //Pegar aqui
       <td>
           //Aqui continua a tabela
       </td>
   </tr>
   <tr> //Pegar aqui
       <td>
           //Aqui continua a tabela
       </td>
   </tr>
</table>

Return I wish to make:

<tr>
    //oque tem dentro
</tr>

<tr>
    //oque tem dentro
</tr>

So we have tables inside tables. I’d like to take the whole list of the first <tr>. But when I select $("table tr"), he enters the other elements and selects everything.

How do I select only the first career of <tr>, and not get inside them?

1 answer

3

To solve the problem I performed the following procedure:

$(b).find("tbody tr:first").siblings().andSelf().each(function(a,b){
    console.log(b)
});
  • @Mauroalexandre answers are in the answer field, and should not be added in the question.

  • Right. I saw on the Soen for a MOD about it. All right.

  • This is not Soen, but at this point it is the same. Question is question, answer is answer. Here are some legal readings about the site: [Help] - There is also the site Meta, to discuss the operation of Sopt, and this post is legal as reference: Community FAQ - There’s this one too, more specific: I answered my own question, did something wrong?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.