Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

90
Visualizações
How to add style using css for my first table row in for loop while using inner html

I just want to add style in my first tr on my inner HTML table how could I do this?

for (i = 0; i <= years_in_months; i++) {
    var powint1 = compound * (Math.pow(interest, i));
    powint1 = powint1.toFixed(0);


    var ointerest = (interest - 1)*100;
    ointerest = ointerest.toFixed(0); 

    tableHTML = tableHTML + "<tr><td>" + months2[i] + "</td><td> " + ointerest + "%"+"</td><td>"+ "$"+powint1 +"</td></tr>";
    document.getElementById("tdisplay").innerHTML = "<thead><tr><th>Month</th><th>Interest</th><th>Total Amount</th></tr></thead>"+ tableHTML;
} 
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Use this in your css:

#tdisplay tr:nth-of-type(1) {
    /* Your Style*/
}

See CSS :nth-of-type() Selector

You may want to move document.getElementById("tdisplay").innerHTML = ... outside the loop

about 4 years ago · Juan Pablo Isaza Relatório

0

I got the answer with my own, I just added class and put the value of i on it then do the CSS.

tableHTML = tableHTML + "<tr class='table-"+[i]+"'><td>" + months2[i] + "</td><td> " + ointerest + "%"+"</td><td>"+ "$"+powint2 +"</td></tr>";

CSS

.table-0{background-color:yellow;}

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda