Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

382
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

I think what you want is window.getComputedStyle

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

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda