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 6728171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:08:16+00:00 2026-05-26T10:08:16+00:00

So if there is a css file linked to a webpage like: <link href=style.css

  • 0

So if there is a css file linked to a webpage like:

<link href="style.css" rel="stylesheet" type="text/css">

and i want to read a certain property, e.g a div has className=’layout’ and i want to read the details of this property using JavaScript, how can i do that?

I have searched a lot but almost have no luck, please suggest.

  • 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-05-26T10:08:16+00:00Added an answer on May 26, 2026 at 10:08 am

    You have got two options:

    1. Manually enumerating and parsing the document.styleSheets object (not recommended, unless you want to get all specific style properties defined by a certain selector).
    2. Create an element matching the selector, and use the getComputedStyle or currentStyle (IE) method to get the property value.

    In your example, attempt to get a certain property (let’s say: color) of a div with class="layout":

    function getStyleProp(elem, prop){
        if(window.getComputedStyle)
            return window.getComputedStyle(elem, null).getPropertyValue(prop);
        else if(elem.currentStyle) return elem.currentStyle[prop]; //IE
    }
    window.onload = function(){
        var d = document.createElement("div"); //Create div
        d.className = "layout";                //Set class = "layout"
        alert(getStyleProp(d, "color"));       //Get property value
    }
    

    Regarding comment at your question, another function:
    The function below will ignore inline style definitions of the current element. If you want to know the style definitions inherited from a stylesheet (without inherited style definitions of the parent elements), traverse the tree, and temporary wipe the .cssText property, as shown in the funcion below:

    function getNonInlineStyle(elem, prop){
        var style = elem.cssText; //Cache the inline style
        elem.cssText = "";        //Remove all inline styles
        var inheritedPropValue = getStyle(elem, prop); //Get inherited value
        elem.cssText = style;     //Add the inline style back
        return inheritedPropValue;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so if there is an external css file like: <link rel='stylesheet' type='text/css' href='test.css'> and
Is there a way to load external CSS files, like we load JS file
There are two accordions on my page, with custom accordion CSS in another file,
Is there a disadvantage to using a dynamic Python file to generate the CSS
Is there CSS Meta Framefork for ASP.NET? Something like LESS or xCSS.
Is there a CSS style that IE7 and Firefox will obey that changes the
Is there a CSS code that changes this text This is it to this
Are there any good CSS coding style/standards?
Say there is a css style declaration to an element which has been set
I have the following style in an external CSS file called first.css table {

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.