Phillip Senn
Phillip Senn

Reputation: 47595

jQuery :last-child selector

How do I add class="x" to the last table cell that's on the same row as the one that has class="insert"? Something like:

$('td.insert').parents('tr').(':last-child').addClass('x');

Upvotes: 0

Views: 2502

Answers (2)

Ivo Sabev
Ivo Sabev

Reputation: 5230

$('td.insert').siblings(':last-child').addClass('x');

Upvotes: 2

Nick Craver
Nick Craver

Reputation: 630379

You can do that like this:

$('td.insert').siblings(':last-child').addClass('x');

This filters the sibling cells, leaving only the last child to add the class to.

Upvotes: 4

Related Questions