Lluís Puig Ferrer
Lluís Puig Ferrer

Reputation: 1146

jQuery: Adding td elements with one class to tr

First of all I have to find the number of cells with one class, this line works.

var numcells = $('.hidden-td').length

And now I have to find the element with the class .placeholder-style I use this line (only one <tr>have this class):

$(this).find('.placeholder-style') 

Now I have to add the same number of var numcellslike <td>inside the <tr>with the clase .hidden-td I think this will be with .addClass('hidden-td').

How can I make this?

Thanks

Upvotes: 2

Views: 61

Answers (1)

ProEvilz
ProEvilz

Reputation: 5455

I'm assuming this is the correct structure you're after... if not, post your HTML so I can amend it but either way, this is how you should do it.

var numcells = $('.hidden-td').length;

var content = $(this).find('.placeholder-style');

for (i = 0; i < numcells; i++) { 
    content.append('<td class="hidden-td"></td>');
}

Upvotes: 2

Related Questions