Paul Attuck
Paul Attuck

Reputation: 2269

Find in jQuery only for first nested tree?

<table id="tab">
    <tr><td>dsf</td><td>dsf</td></tr>
    <tr><td>dsf</td><td>dsf</td></tr>
    <tr><td>dsf</td><td>
        <table id="tab2">
            <tr><td>dsf</td><td>dsf</td></tr>
            <tr><td>dsf</td><td>dsf</td></tr>
        </table>

        </td></tr>
</table>

#tab td {
border: solid 1px red;
}

#tab2 {
background-color: green
}

$("#tab").find("tr").css("background-color", "red");

This function find all TR in #tab. i would like find only first TR, not nested TR.

Is possible without add class for TR? i would like make this only with jQuery.

Upvotes: 0

Views: 1834

Answers (2)

SLaks
SLaks

Reputation: 887547

find finds all descendant elements.

It sounds like you want .children('tr').

You can also do $('#tab > tr')

Upvotes: 3

Joseph Marikle
Joseph Marikle

Reputation: 78550

$("#tab>tr").css("background-color", "red");

that would do what I think you are trying to do XD

Otherwise you could try

$("#tab").find("tr:first-child").css("background-color", "red");

question was unclear :P

Upvotes: 1

Related Questions