Put <td> below <th> having similar values

Put <td> below <th> having similar values

Hi folks, 

Actually I have a table organized in this way :

CompanyName | Red | Blue | Yellow company1 Blue Yellow Red

And I would like to dynamically put similar elements bellow <th> having the same value

CompanyName | Red | Blue | Yellow company1 Red Blue Yellow

Many thanks for any help in these regards. Below is my try.. but doesn't seem to be successful

var headers = []; var row = []; $("#dashboard > thead > tr > th").each(function(k,v){ var header = cleanHeader($(this).text()); $("#dashboard > tbody > tr > td").each(function(k,v){ var td = cleanCertificate($(this).text()); if (td === header) { $(this).text($(this).text()); } }); }); }