Skip to content

Instantly share code, notes, and snippets.

@gustinmi
Last active January 26, 2017 10:46
Show Gist options
  • Save gustinmi/204c5c7c268ece7f4d316fb474f7cb7a to your computer and use it in GitHub Desktop.
Save gustinmi/204c5c7c268ece7f4d316fb474f7cb7a to your computer and use it in GitHub Desktop.
var myStyle = function getStyle(className_) {
var styleSheets = window.document.styleSheets;
var styleSheetsLength = styleSheets.length;
for(var i = 0; i < styleSheetsLength; i++){
var classes = styleSheets[i].rules || styleSheets[i].cssRules;
if (!classes)
continue;
var classesLength = classes.length;
for (var x = 0; x < classesLength; x++) {
if (classes[x].selectorText == className_) {
var ret;
if(classes[x].cssText){
ret = classes[x].cssText;
} else {
ret = classes[x].style.cssText;
}
if(ret.indexOf(classes[x].selectorText) == -1){
ret = classes[x].selectorText + "{" + ret + "}";
}
return ret;
}
}
}
};
myStyle("body")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment