Javascript dynamically changes CSS files using cssRule

  • 2020-03-30 03:44:57
  • OfStack


 _.find(document.styleSheets[4].cssRules,function(cssRule){ 
if(cssRule.selectorText && cssRule.selectorText.indexOf(".navbar-fixed-top2")>-1){ 
cssRule.style.position=""; 
cssRule.style.top = "0px"; 
} 
if(cssRule.selectorText && cssRule.selectorText.indexOf("#pageIndi_content, #page1_l1_content, #page_appList") >-1){ 
cssRule.style.padding = "0px"; 
} 
if(cssRule.selectorText && cssRule.selectorText.indexOf("#page1_index_content") >-1){ 
cssRule.style.padding = "0px"; 
} 
});

The loop USES the underscore, which cannot use the following code directly when using the cssRule, otherwise it will not take effect


cssRule.style=" left: 0;position:'';right: 0; top: 0px;z-index: 1031;";

Can only use


cssRule.style.padding = "0px";

Related articles: