CSS syntax alerts in ES [closed]

0

Could an ES subroutine be made to notify me in any way of a CSS syntax error?

    
asked by Vyber90 13.04.2017 в 19:24
source

1 answer

3

This code taken from link is used to validate CSS:

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');
}

// Ejemplo: getDefinedCss('myclassname')
    
answered by 13.04.2017 в 20:53