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

152
Visualizações
JS can't set style property

Ok let's look at this part of the code -

$(tbody).find('tr').each((i, oldTbodyTr) => {
    newTr = document.createElement('tr');
    $(oldTbodyTr).find('td').each((i, oldTd) => {
        let newTd = document.createElement('td');
        newTd.innerHTML = oldTd.innerHTML;
        newTd.classList = oldTd.classList;
        newTd.style = oldTd.style; //Doesn't work
        newTr.appendChild(newTd);
    });
    newTableTbody.appendChild(newTr);
});

It creates a new table body by looping through all rows in tbody of an already existing table. Everything is fine, except that the style of the old td doesn't transfer to the new td element. I can't figure out why.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you want to copy inline styles, you could try newTd.style.cssText = oldTd.style.cssText since style itself is immutable.

See more about style.cssText.

const source = document.getElementById('source');
const target = document.getElementById('target');

target.style.cssText = source.style.cssText;
<p id="source" style="color: red; background-color: blue; font-size: 20px;">Source</p>
<p id="target">Target</p>

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