Search code examples
jquerycssdhtml

jQuery replicating attributes of one table's headers to all table data cells in another table


I have the following jQuery which will allow me to update the widths and classes from the header of one table onto the data cells of another.

Currently the following only updates the first row in the other table but i need it to update all the widths and classes in the other table for consistency :(

$($orginalHeaders).each(function(index) {
    $headWidth = $(this).attr('width');
    $headClass = $(this).attr('class');        
    $('#quotations').find('tbody tr td:eq(' + index + ')').attr({
        width: $headWidth,
        class: $headClass
    });
});

Solution

  • Try

    $('#quotations tbody tr').each(function(){
        $(this).find('td:eq(' + index + ')').css('width', $headWidth).addClass($headClass);        
    });