Skip to content

Instantly share code, notes, and snippets.

@breezhang
Created June 25, 2014 06:14
Show Gist options
  • Save breezhang/db8059454d871f28aada to your computer and use it in GitHub Desktop.
Save breezhang/db8059454d871f28aada to your computer and use it in GitHub Desktop.
chrome color log
//defile out style debug css code
//eg;
.xxy {
color:green;
font-size:16px;
font-weight:bold;
}
// js code read and format css
//help function
function getStyle(className) {
var l = document.styleSheets.length;
for(var i=0;i<l;i++){
var classes = document.styleSheets[i].rules || document.styleSheets[i].cssRules;
for(var x=0;x<classes.length;x++) {
if(classes[x].selectorText==className) {
return ((classes[x].cssText) ? classes[x].cssText : classes[x].style.cssText).replace(/({)|(})|className/g,"");
}
}
}
}
//===============just call ============================
console.log("%c this is demo ",getStyle('.xxy'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment