Created
September 4, 2014 21:45
-
-
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...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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