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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:04:56+00:00 2026-05-15T17:04:56+00:00

I have been experimenting with using javascript to dynamically write stylesheets. In Firefox, one

  • 0

I have been experimenting with using javascript to dynamically write stylesheets. In Firefox, one can use the setProperty method on the style for the cssRules of the styleSheets, like…

document.styleSheets[0].cssRules[0].style
  .setProperty(propertyName, propertyValue, 'important');

…to set the !important flag on the style. I have not found an equivalent for this in Internet Explorer (the setAttribute method does not have such an option for setting the !important flag on a style). Some experimentation found that for exact styles, such as border-top-width, I can rewrite the cssText string to add the !important, but then I discovered that if you individually set all the borders, IE rewrites the actual rule to be a short hand form, so it rewrites to border-top, border-right, etc., and each gets set, but without the !important flag. Further, if I explicitly set it via the short hand form, it does not accept a rewrite of the cssText to take the !important flag.

So the question is, does anyone know of a way, when dynamically writing styles to a styleSheets rule, to get IE to consistently set the !important flag for that rule?

Thanks for your help,

Scott

  • 1 1 Answer
  • 1 View
  • 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-15T17:04:57+00:00Added an answer on May 15, 2026 at 5:04 pm

    I have spent some more time doing some testing, and have come to the conclusion that my rewrite of the cssText is working to add !important to some mysterious internal flag setting of IE, even though the shortened properties that itself rewrites for the cssText do not reflect that.

    Apparently, neither the cssText property (if it is examined after my rewrite to add the !important) nor the Microsoft Developer Toolbar examination of the element are showing the fact that the property has an !important setting on it. The element is, however, displaying as if my rewrite worked. I tested this by placing an !important on the base style for an image border like so:

    img {border: 3px solid green !important;}
    

    Then with javascript I created my styleSheets object and added a rule that was both more specific (using the id of the image) and that had its cssText rewritten with !important after already having set the style of the styleSheets object by a javascript call for borderTopColor = red. I then set the inline style of the element to change the top color to yellow. The results were as I would expect with the !important flag. The red wins out, as it is a later (and more specific) call than the original green, and the inline style does not override it. If I remove the rewrite of the!important then the color reverts to green, and if I remove green’s !important the color reverts to yellow.

    I also tested this with the green having a higher selector specificity than my javascript written style for the red. That, too, behaved as expected, with green winning out since it now had the higher selector specificity with the competing !important of the red declaration.

    This was tested on IE8, IE7, and IE6 (yes, it worked there too). While rewriting/setting the cssText of the styleSheets is not as easy as being able to set it with a straight javascript call on the property, at least it works. The real ‘bug’ is the fact that neither the cssText nor the Developer Toolbar were giving me correct information that an !important flag was set on those styles, so if someone were coming behind and examining the site, they may get confused as to why something is happening with the styles (why something that does not seem to be important is acting as if it is).

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

Sidebar

Related Questions

I have been experimenting with using extensions in Microsoft XSLT (1.0). In the JavaScript
I have been experimenting with sending messages from two .NET Windows Forms applications using
I have been experimenting with Firefox's Audio API to detecting silence in audio. (The
I have been experimenting with writing applications that use a local SQL Database to
I have been experimenting recently with Silverlight, RIA Services, and Entity Framework using .NET
For fun I have been experimenting with methods of encryption. One of the methods
I have been experimenting using a Facebook login button on my website. The login
I have been experimenting with Objective-C using GCC + GNUstep on an Ubuntu system.
For the last few years I have been using Firefox, Firebug, and the Web
I have been experimenting and trying to learn JQuery, using AJAX to consume a

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.