Last active
March 29, 2018 23:41
-
-
Save brettz9/990313 to your computer and use it in GitHub Desktop.
getCSSPropertyValue.js
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
| /** | |
| * @example | |
| * getCSSPropertyValue('.someClass', 'color'); | |
| */ | |
| function getCSSPropertyValue (selectorText, propertyName) { | |
| function _getPropertyFromStyleSheet (ss, selectorText, propertyName) { | |
| let value = null; | |
| [...ss.cssRules].some((rule) => { | |
| if (rule.type === CSSRule.STYLE_RULE && | |
| rule.selectorText === selectorText | |
| ) { | |
| value = rule.style.getPropertyValue(propertyName); | |
| return true; | |
| } | |
| }); | |
| return value; | |
| } | |
| let value = null; | |
| [...document.styleSheets].some((ss) => { | |
| value = _getPropertyFromStyleSheet(ss, selectorText, propertyName); | |
| return value; | |
| }); | |
| return value; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment