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

0

299
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>

almost 3 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>

almost 3 years ago · Juan Pablo Isaza Report

0

I think what you want is window.getComputedStyle

const weight = window.getComputedStyle(elem).fontWeight
almost 3 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>

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