find classes according to a regular expression

Solutions on MaxInterview for find classes according to a regular expression by the best coders in the world

showing results for - "find classes according to a regular expression"
Carl
15 Feb 2017
1// find classes with scrollbars
2// input regular expression pattern as input argument
3 function findClass( pattern ){
4   var allClassesTmp = {}, allMatchedClasses = [];
5   var rx = pattern ? (new RegExp(pattern)) : (new RegExp(".*"));
6
7   $('*[class]').each( function(){ 
8     var cn = this.className.split(/\s+/); 
9     for(var i=cn.length;--i>-1;){ 
10       if(rx.test(cn[i]))allClassesTmp[ cn[i] ] = 1
11     } 
12   });
13   var size = Object.keys(allClassesTmp).length;
14   console.log('total number:', size)
15   for(var i in allClassesTmp){
16     let attr = $('.'+i).css('overflow-y') == 'auto';
17     console.log(attr);
18     if (typeof attr !== typeof undefined && attr !== false) {
19
20       console.log('className',i);
21       console.log("Scroll Heights:",document.querySelector('.'+i).scrollHeight);
22       allMatchedClasses.push(i)
23
24       if(document.querySelector('.'+i).scrollHeight > document.querySelector('.'+i).clientHeight){
25         console.log(i);
26         allMatchedClasses.push(i)
27       }
28     }
29   };
30   return allMatchedClasses;
31 }