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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:44:00+00:00 2026-06-07T09:44:00+00:00

I know it is not common way to modify CSS classes… but anyway >>

  • 0

I know it is not common way to modify CSS classes… but anyway >> I have the following function to change CSS parameter with JavaScript:

function changeCSSParameter(classId, param, value)
{
  var CSSRules;
  if (document.all)
  {
    CSSRules = 'rules';
  }
  else if (document.getElementById)
  {
    CSSRules = 'cssRules';
  }
  for (var i = 0; i < document.styleSheets[0][CSSRules].length; i++)
  {
    var classes = document.styleSheets[0][CSSRules][i].selectorText.split(/\s*,\s*/);
    for (var j = 0; j < classes.length; j++)
    {
      if (classes[j] == classId)
      {
        document.styleSheets[0][CSSRules][i].style.setProperty(param, value, '');
      }
    }
  } 
}

However this function would not work as I wish if style classes are defined in groups, such as

.first, .second
{
  color: red;
}

…because any change would apply to both classes. How can I solve this issue? Please advice.

No jQuery, please, just old-fashion JavaScript.

  • 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-07T09:44:01+00:00Added an answer on June 7, 2026 at 9:44 am

    My first question is how sure you are about the inference that the existence of document.all implies that a stylesheet will have a rules property and its nonexistence implies that it will have a cssRules property? Because that seems rather sketchy to me? What is it based on?

    But assuming that it is a reasonable inference, why in the world are you making that CSSRules calculation on every call to your function? Calculate it once at start-up and store it, returning your function inside a closure that contains the value.

    That said, on to your main problem…

    Your code will only work if the individual selectors (inside the comma-separated groups of selectors) are single class selectors such as .myClass. Anything even slightly more complicated, such as div.myClass won’t work, correct? If that’s all you’re trying to do, I think I have a (fairly obnoxious, but workable) solution: On encountering a comma-separated solution where one of them is a match, write new rules for each of the selectors, cloning the existing rule. Then for the one that matches your class name, change the relevant property. Finally, remove the original rule.

    It’s not fun, and it makes several assumptions that are clearly not warranted in the general case, but look like they might match what you’re trying to do in your code.

    Hey, I did say it was obnoxious! 🙂

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

Sidebar

Related Questions

I do not know javascript right now but I am planning on learning it.
I do not know if this is possible, but here goes. And working with
So I'm not sure if there is a better way to do this, but
I know not my .htaccess is working since it is showing the ErrorDocument 404
In an ASP.Net WAP, the home page /default.aspx is receiving periodic requests from I-know-not-where.
I do not know how to ask this question. So I will just give
I do not know why my google markers are not showing. I am using
I do not know what I am doing when it comes to JSON. So
I know your not really supposed to use Flash and SWF's in a Sencha
I do not not know much about Regex, I want to try parsing sting

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.