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

384
Visualizações
Get CSS font-weight value using Javascript style.fontWeight.value (getting undefined, expecting a value)

I am aware that the value could sometimes be a word like "bold" but for this i am only using numbers and was expecting the output to show "900", instead i'm getting "undefined".

document.getElementById("results").innerText = document.getElementById("getfontweightfrom").style.fontWeight.value;
<div id="getfontweightfrom" style="font-weight:900;">
Test
</div>
<hr>
Result: <div id="results"></div>

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

0

No need to add .value.

document.getElementById("results").innerText = document.getElementById("getfontweightfrom").style.fontWeight;
<div id="getfontweightfrom" style="font-weight:900;">
Test
</div>
<hr>
Result: <div id="results"></div>

about 4 years ago · Juan Pablo Isaza Relatório

0

I think what you want is window.getComputedStyle

const weight = window.getComputedStyle(elem).fontWeight
about 4 years ago · Juan Pablo Isaza Relatório

0

You may use getComputedStyle()

elem = document.getElementById('getfontweightfrom');
style = window.getComputedStyle(elem);
weight = style.fontWeight;
alert(style.fontWeight)
<div id="getfontweightfrom" style="font-weight:900;">Test<div>

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