Adding! Important in dynamically written stylesheet for Internet Explorer

I experimented using javascript to dynamically write stylesheets. In Firefox, you can use the setPropertystyle method for cssRules styleSheets, for example ...

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

... set a flag !importantin style. I did not find the equivalent for this in Internet Explorer (the method setAttributedoes not have such an option to set the flag !importantin style). Some experiments showed that for fine styles, such as border-top-width,, I can rewrite the string cssTextto add !important, but then I found that if you individually set all the boundaries, IE rewrites the actual rule as short so it rewrites border-top, border-rightetc., and everyone gets a value, but without a flag !important. Also, if I explicitly set it using the short form, it does not accept the rewrite entry cssTextto take the flag !important.

So the question is, does anyone know of a way to dynamically write styles in a rule styleSheetsto force IE to set the flag !importantfor this rule in sequence ?

Thank you for your help,

Scott

+3
source share
2 answers

I spent a little more time on some testing and came to the conclusion that my processing cssText works on adding the !importantIE flag to the mysterious internal setting, even if the shorter properties that are overwritten for cssTextdo not reflect this.

-, cssText ( !important), Microsoft Developer Toolbar , !important , , , , . , !important :

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

javascript stylesSheets , ( id ) cssText !important style styleSheets javascript borderTopColor = red. , . , !important. , ( ) , , . !important, , !important, .

, , javascript- . , , , !important .

IE8, IE7 IE6 (, ). / cssText styleSheets , JavaScript , , . "" , cssText, , !important, , - , - ( , , , ).

+2

, css, ! . , , IE .

0

Source: https://habr.com/ru/post/1753311/


All Articles