UNPKG

@kard/webpack-config

Version:
38 lines (34 loc) 1.09 kB
/** * Returns content of a css class * @param {string} className_ - name of class * @return {string} - content of the class or undefined * @example * getStyle('.myclass') */ 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; } } } } module.exports = { getStyle }