Answers for "find a class name that maches a pattern"

0

find a class name that maches a pattern

var listClasses = function( pattern ){
    var allClassesTmp = {}, allClasses = []; 
    var rx = pattern ? (new RegExp(pattern)) : (new RegExp(".*"));

    $('*[class]').each( function(){ 
        var cn = this.className.split(/\s+/); 
        for(var i=cn.length;--i>-1;){ 
            if(rx.test(cn[i]))allClassesTmp[ cn[i] ] = 1 
        } 
    }); 
    for(var i in allClassesTmp)allClasses.push(i); 
    return allClasses;
}
Posted by: Guest on July-03-2020

Code answers related to "find a class name that maches a pattern"

Browse Popular Code Answers by Language