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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:06:10+00:00 2026-05-27T15:06:10+00:00

I have a JS library using canvas that needs to get its colors from

  • 0

I have a JS library using canvas that needs to get its colors from CSS classes. The classes used by the library are predetermined, but which stylesheet (out of possibly many) is not.

With a class like this:

.a_preset_class {
    margin: 10pt;
    color: rgba(216,34,21,0.5);
}

I would like to be able to write something like this:

context.strokeStyle = getClassColor("a_preset_class");

and have context.strokeStyle be set to "rgba(216,34,21,0.5);"

The obvious way is to traverse document.styleSheets, but I’m hoping there’s a less drastic way that I’m unaware of.

  • 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-27T15:06:11+00:00Added an answer on May 27, 2026 at 3:06 pm

    If you are able to use Dojo in your site, you can use dojox.data.CssRuleStore to make a searchable store of all of your CSS rules. You then use the standard fetch() method to search the store, using the style rule’s “selector” property as your search term. E.g.,

    ruleStore = dojox.data.CssRuleStore(); // make it a global if it's not part of a widget
                                           // so that it's accessible by the other methods
                                           // below when calling ruleStore.getValue()
    var rulesFound = [];
    
    // When querying the store, you can either do an exact match search such as ".myClass",
    // or do a wildcard-based search such as ".myClass*" (find all rules that start with
    // ".myClass", "*.myClass*" (all rules containing ".myClass" somewhere in the selector),
    // "?someValue" (any rules that have an arbitrary first character, followed by
    // "someRule"), etc.
    var queryObj = {"selector": ".a_preset_class"};
    
    var checkEmpty = function(count, request) {
        if (count < 1)
            // do your empty response logic here
    };
    
    var processRule = function(item, request) {
        rulesFound.push(ruleStore.getValue(item, "style"); // Add the item's CSSStyleDeclaration object with all assigned values to the results array
    };
    
    ruleStore.fetch({query: queryObj, onBegin: checkEmpty, onItem: processRule});
    

    Using this code as a starting point, you could create a function that takes the desired search term as its parameter, passes that in to the query, and then returns the array of CSS rules that were found. Then you can just iterate the response array after calling the function, and make whatever changes are needed.

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

Sidebar

Related Questions

I have a library that serves using events data came in from async tcp
I have a cpp file from which I am generating a shared library (using
I have a C++ library that I build using Scons which is eventually linked
I have a shared library that I wish to link an executable against using
Hi i'm working in a class library using C#, and i have some classes
I am working on a class library using C#. I have designed 3 main
I have a static library *.lib created using MSVC on windows. The size of
I have a WCF Service Library (implemented using NH) with one of the class
I've started using Enterprise Library and have the following questions: 1)How do I add
I have an project csproj, with app.config file, and logging Ent.Library section using configsource

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.