ehabd
ehabd

Reputation: 1077

Take a TD, and insert it after the second TD in the parent TR

I have a table. I want to take all ninth TDs in each TR, and place it after the first original TD in that same TR.

This code takes the ninth TD, and places it right after the parent TR. I want to place it after the first original TD in that same TR:

$('td:nth-child(9)').each( function(){
   $(this).prependTo($(this).parent());
});

What I need is an equivalent of:

.parent():first-child

Upvotes: 0

Views: 701

Answers (2)

adeneo
adeneo

Reputation: 318302

$('td:nth-child(9)').each( function(){
    $(this).siblings('td:first').after(this);
});

FIDDLE

Upvotes: 2

Codegiant
Codegiant

Reputation: 2150

try this

$('td:nth-child(9)').each( function(){

            $(this).siblings('td').eq(0).after(this);
 });

Upvotes: 2

Related Questions