Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

383
Views
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 answers
Answer question

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 Report

0

I think what you want is window.getComputedStyle

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

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!