0

How would you go about adding column specific classes to the table below with JQuery traversing? ( last column in my case )

i started to dab around quite hoplessly with something along the line of

$('#myID tr').children("td:not(:first)").addClass("me");

like I said, hopelessly. Please pass me some help.

<table id="myID" class="myClass">
    <tr>
        <th>one</th>
        <th>two</th>
        <th>three</th>
        <th>four</th>
    </tr>
    <tr>
        <td>1</td>
        <td>2</td>
        <th>3</th>
        <th>4</th>
    </tr>
    <tr>
        <td>a</td>
        <td>b</td>
        <th>c</th>
        <th>d</th>
    </tr>
</table>

SOLUTION:

$('#myID tr').children("td:nth-last-of-type(1)").addClass("me");

1 Answer 1

2

Try first-of-type instead

$('#myID tr').children("td:not(:first-of-type)").addClass("me");

Or first-child

$('#myID tr').children("td:not(:first-child)").addClass("me");

Demo

Sign up to request clarification or add additional context in comments.

1 Comment

@mornenel You forgot to include jQuery library see this!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.