Skip to content

Instantly share code, notes, and snippets.

@brettz9
Last active March 29, 2018 23:41
Show Gist options
  • Select an option

  • Save brettz9/990313 to your computer and use it in GitHub Desktop.

Select an option

Save brettz9/990313 to your computer and use it in GitHub Desktop.
getCSSPropertyValue.js
/**
* @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