Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. javascript validate css
  2. function getDefinedCss(s){
  3.     if(!document.styleSheets) return '';
  4.     if(typeof s== 'string') s= RegExp('\b'+s+'\b','i'); // IE capitalizes html selectors
  5.  
  6.     var A, S, DS= document.styleSheets, n= DS.length, SA= [];
  7.     while(n){
  8.         S= DS[--n];
  9.         A= (S.rules)? S.rules: S.cssRules;
  10.         for(var i= 0, L= A.length; i<L; i++){
  11.                 tem= A[i].selectorText? [A[i].selectorText, A[i].style.cssText]: [A[i]+''];
  12.                 if(s.test(tem[0])) SA[SA.length]= tem;
  13.         }
  14.     }
  15.     return SA.join('nn');
  16. }
  17.  
  18. // Then you check the class if exists by calling getDefinedCss('myclassname')