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

  • Home
  • SEARCH
  • 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 8278089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:53:20+00:00 2026-06-08T08:53:20+00:00

edit added a test with regexpr to solve the problem techfoobar pointed out edit

  • 0

edit
added a test with regexpr to solve the problem techfoobar pointed out

edit 2
corrected code for others hf 🙂

I’m looking for a way to get all static styles from a specified class. I don’t want to append a new div and extract all possible values from it because values are often just computed…

Here are some related posts:

jQuery CSS plugin that returns computed style of element to pseudo clone that element?

Can jQuery get all CSS styles associated with an element?

http://quirksmode.org/dom/w3c_css.html

This is what i came up so far:

function getExternalCSS(className) {
    var cssText = false;
    $.each(document.styleSheets, function(key, value) {
        $.each(value.cssRules, function(k, v) {
            if(new RegExp(className, "i").test(v.selectorText)) {
                cssText = v.cssText;
                return false;
            }
        });
        if(cssText !== false) {
            return false;
        }
    });
    return cssText;
}

css to browse:

.someClass {
    style1...
}
.someOtherClass {
    style2...
}
.myClassToFind {
    style3...
}

usage:

    getExternalCSS(".myClassToFind");  //note the . for class

The selectorText is returned correctly, but the if is never triggered. I already tried to parse to string etc. Any ideas?

  • 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-08T08:53:21+00:00Added an answer on June 8, 2026 at 8:53 am

    Update

    Check this demo: http://jsfiddle.net/XaB3T/1/

    There were a couple of problems:

    a) You need to return false from a $.each to stop the looping, its like break. This was not being done.
    b) You were checking v.selectorText.toLowerCase() with '.myClass' which surely cannot match since '.myClass' is not all small case


    Explanation for For counting in only those styles that will be applied at the end, you might need to do a lot more!

    For CSS specificity rules, please refer to:

    • http://www.htmldog.com/guides/cssadvanced/specificity/
    • http://coding.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/
    • http://reference.sitepoint.com/css/specificity
    • http://css-tricks.com/specifics-on-css-specificity/

    The if never returns true because:

    a) The selector text need not be exactly .yourClass. It can be .a .yourClass, div.yourClass or even .anotherClass, .yourClass etc.. all pointing to your element

    b) The check needs to be something like:

    for each selectorText {
       strip off any { character
       split the selector text by ',' into an array called parts
       for each part {
          check if it ends with '.yourClass' // if it does, this class is match
       }
    }
    

    Another problem is CSS specificity. For counting in only those styles that will be applied at the end, you might need to do a lot more!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: Added code (Exception on line 095, 5th time it's hit.) public DataTable ParseBarcodes(String[]
Edit: You can get the full source here: http://pastebin.com/m26693 Edit again: I added some
EDIT : Accepted answer points out what my issue was. I added another answer
I have a piece of code: EDIT: The _penParams are initialized as the added
In the following code why does mockTest.ToString() return Null? EDIT: Added comment into example
All the code is inline here: http://shanxinc.com/test/fancybox2/ All I'm trying to do is get
edit: I have added a few new lines of code to the beginning for
Edit: added some error checking code and found error '1282' is being thrown when
EDIT: I added in where I create new instance of the class Process as
EDIT I added this note to explain why I keep this question here. I

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.