How do you read CSS rule values with JavaScript?

后端 未结 16 1169
天涯浪人
天涯浪人 2020-11-21 21:02

I would like to return a string with all of the contents of a CSS rule, like the format you\'d see in an inline style. I\'d like to be able to do this without knowing what i

16条回答
  •  别跟我提以往
    2020-11-21 21:39

    I made a similar helper function which shows the unneeded styles for this page. appends a

    to the body listing all styles that where not used.

    (to be used with the firebug console)

    (function getStyles(){var CSSrules,allRules,CSSSheets, unNeeded, currentRule;
    CSSSheets=document.styleSheets;
    
    for(j=0;j"; 
      }       
     }
    }
    
    docBody=document.getElementsByTagName("body")[0];
    allRulesContainer=document.createElement("div");
    docBody.appendChild(allRulesContainer);
    allRulesContainer.innerHTML=unNeeded+isHover;
    return false
    })()
    

提交回复
热议问题