Skip to content

Instantly share code, notes, and snippets.

@darbicus
Created September 4, 2014 21:45
Show Gist options
  • Save darbicus/d7351dc4636cb2c544fb to your computer and use it in GitHub Desktop.
Save darbicus/d7351dc4636cb2c544fb to your computer and use it in GitHub Desktop.
getElementCssStyleRules is a function to return an array of the css rules that affect the element supplied to the function...
var getElementCSSStyleRules = function (f) {
var myElement = f;
var r = [];
[].slice.call(document.styleSheets).forEach(function (rules) {
[].slice.call(rules.rules).forEach(function (e) {
if ([].slice.call(document.querySelectorAll(e.selectorText)).indexOf(f) !== -1) {
e.toString = function(){return this.selectorText;};
r.push(e);
}
});
});
return r;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment