omega
omega

Reputation: 43893

Jquery select statement

If I have a html structure like this

<table>
    <tbody>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </tbody>
</table>
<table>
    <tbody>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </tbody>
</table>
<table>
    <tbody>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </tbody>
</table>
etc...

Where the table tags just repeat. How would could I write a select statement that would get the third td tag from every table tag?

Thanks

Upvotes: 0

Views: 213

Answers (4)

Toni Michel Caubet
Toni Michel Caubet

Reputation: 20173

You can actually use:

$('table tbody tr td:last-child')

wich would work in css3, too:

table tbody tr td:last-child{
    background:red;
}

Upvotes: 0

user2520440
user2520440

Reputation:

Try this: $("td:nth-child(2)").append(" - 2nd!");

Upvotes: 0

wirey00
wirey00

Reputation: 33661

just use nth-child selector

$('td:nth-child(3)')

Upvotes: 1

karthikr
karthikr

Reputation: 99660

You can do:

$('table tr td:nth-child(3)')

Here is a fiddle demo

Upvotes: 5

Related Questions