Tariq
Tariq

Reputation: 2569

How to select <tr> that has <td>'s only, but not <th> using jQuery?

I have a table with headers and table data. Essentially look like this:

<table>
    <tr>
        <th>Start Time</th><th>End Time</th>
    </tr>
    <tr>
        <td>12:00 am</td><td>01:00 am</td>
    </tr>
    <tr>
        <td>01:00 am</td><td>02:00 am</td>
    </tr>
    <tr>
        <td>12:00 pm</td><td>01:00 am</td>
    </tr>
</table>

Now I want to select data rows only. Header row should not be selected. I don't want to add a class to my td or tr elements

I have to do this in JQuery, so JQuery specific solution is acceptable too.

Any clue.

Upvotes: 2

Views: 4405

Answers (1)

Milind Anantwar
Milind Anantwar

Reputation: 82241

You can use :has selector to get tr that have td elements in it:

$('tr:has(td)').css('name','value')

Upvotes: 8

Related Questions