See the code snippet below, the function returns the found class or identifier from the stylesheet or the style tag that we pass. And returns an empty string if it is not found.
<script type="text/javascript"> function getDefinedCss(s){ if(!document.styleSheets) return ''; if(typeof s== 'string') s= RegExp('\\b'+s+'\\b','i'); // IE capitalizes html selectors var A, S, DS= document.styleSheets, n= DS.length, SA= []; while(n){ S= DS[--n]; A= (S.rules)? S.rules: S.cssRules; for(var i= 0, L= A.length; i<L; i++){ tem= A[i].selectorText? [A[i].selectorText, A[i].style.cssText]: [A[i]+'']; if(s.test(tem[0])) SA[SA.length]= tem; } } return SA.join('\n\n'); } console.log(getDefinedCss ('ui-helper-hidden')); </script>
Let me know if this works for you.
Patrick r
source share