Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7919921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:01:48+00:00 2026-06-03T16:01:48+00:00

If I want to read the opacity value in to javacript I can just

  • 0

If I want to read the opacity value in to javacript I can just use

element.style.opacity 

but if I want the fontSize I have to use the function below.

function findFontSize( element_id )
{
    var element = document.getElementById( element_id );  
    // var theCSSprop = element.style.fontSize; // Does not work  
    // var theCSSprop = element.getPropertyValue("font-size"); // Does not work
    var theCSSprop = window.getComputedStyle( element, null ).getPropertyValue("font-size");  // This works
    alert( theCSSprop ); 
}

Related

http://jsfiddle.net/tUc5v/

Why is this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:01:49+00:00Added an answer on June 3, 2026 at 4:01 pm

    There is a different syntax for explicitly defined css styles and inherited styles. I’m guessing (though your jsfiddle doesn’t match the question) that opacity is being explicitly set, but fontSize is inherited.

    UPDATE:
    Found this old comment, thought I’d give a little more…

    If an element does not have a style explicitly defined in a stylesheet or inline then it falls back to the computed style which is not accessible via the element.style.property way.

    Another difference is, explicit styles on the style object are camelCase, but computed styles are hyphen-case.

    Another thing to note is that properties accessed via the style object are 3x-4x faster than window.getComputedStyle (or document.defaultView.getComputedStyle).

    Here’s a basic function that can do this for any style (it doesn’t check for incorrect input, etc..)

    /**
     * 
     * @param el Element
     * @param CSS property in hyphen case 
     * @param pseudo pseudo selector (optional, e.g. '::before')
     */
    function getStyleValue(el, property, pseudo) {
        // convert hyphen-case to camelCase
        const elStyle = el.style[property.replace(/(\-[a-z])/g, $1 =>  $1.toUpperCase().replace('-',''))];
        return ((elStyle !== '' && !pseudo) 
            ? elStyle
            : window.getComputedStyle(el, pseudo).getPropertyValue(property));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file. I want read that file. But In that if
I try to read pdf file. I want to use this function databuffer =
I have to set dropdownlost to read only. I can set enabled =false. But
I want to track users who have read my mails.I am doing this but
I am just drawing a blank here. Have a class that I want read
Hi I can't understand this error I want read this XML file: <?xml version=1.0
I have a specific object with image data. And I want read/write images (in
i want to read an html file by using jquery get function, replace some
I want to read the pdf file from raw folder if devices have any
I want to read .ppt files from the iPhone mail app. I have already

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.