Answers for "find classes according to a regular expression"

0

find classes according to a regular expression

// find classes with scrollbars
// input regular expression pattern as input argument
 function findClass( pattern ){
   var allClassesTmp = {}, allMatchedClasses = [];
   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
     } 
   });
   var size = Object.keys(allClassesTmp).length;
   console.log('total number:', size)
   for(var i in allClassesTmp){
     let attr = $('.'+i).css('overflow-y') == 'auto';
     console.log(attr);
     if (typeof attr !== typeof undefined && attr !== false) {

       console.log('className',i);
       console.log("Scroll Heights:",document.querySelector('.'+i).scrollHeight);
       allMatchedClasses.push(i)

       if(document.querySelector('.'+i).scrollHeight > document.querySelector('.'+i).clientHeight){
         console.log(i);
         allMatchedClasses.push(i)
       }
     }
   };
   return allMatchedClasses;
 }
Posted by: Guest on July-09-2020

Code answers related to "find classes according to a regular expression"

Code answers related to "Javascript"

Browse Popular Code Answers by Language