• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

298
Views
Obtenga el valor de peso de fuente CSS usando Javascript style.fontWeight.value (sin definir, esperando un valor)

Soy consciente de que el valor a veces podría ser una palabra como "negrita", pero para esto solo estoy usando números y esperaba que la salida mostrara "900", en lugar de eso, obtengo "indefinido".

 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>

almost 3 years ago · Juan Pablo Isaza
3 answers
Answer question

0

No es necesario agregar .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>

almost 3 years ago · Juan Pablo Isaza Report

0

Creo que lo que quieres es window.getComputedStyle

 const weight = window.getComputedStyle(elem).fontWeight
almost 3 years ago · Juan Pablo Isaza Report

0

Puede usar getComputedStyle()

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

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error