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