Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

changing CSS with JS, using a function - strips all CSS and re-adds classes passed by 2nd parameter - as an Array

function changeCSS(select, cssArray){
    //function that Removes ClassList
    //then adds back that that DOM element
    // this only works because elem is stored in Memory
    var myArray = [];
    
    var elem = document.getElementsByClassName(select);
    for(var i=0; i<elem.length; i++){
       myArray.push(elem[i]);     
    }  
    myArray.forEach((item, index)=>{
      console.log(myArray);
      myArray[index].removeAttribute('class');
      myArray[index].classList.add(select);
    });
    
    for(var ii=0; ii<elem.length; ii++){
      cssArray.forEach((item, index)=>{
        myArray[ii].classList.add(item);
      });
    }  
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: reading data from link in javascript 
Javascript :: element vs node 
Javascript :: How to determine dropdown should show upward or downward direction 
Javascript :: javascript shorthand ternary 
Javascript :: how to place text input cursor to start in react native 
Javascript :: ex:h2p 
Javascript :: gsheet function argument a1notation 
Javascript :: props with ternary in react 
Javascript :: js merge 2 index declarations for loop 
Javascript :: how to regexp replace with uppercase on specific capture group in js 
Javascript :: convert milliseconds to hours minutes seconds javascript 
Javascript :: jquery show function to javascript code 
Javascript :: how to refresh a page in javascript 
Javascript :: create-react-app height issues with flex 
Javascript :: convert js to typescript online 
Javascript :: How to extract dynamic variable from < bracket in javascript 
Javascript :: add operator in javascript 
Javascript :: Create Compond from route to js function communication 
Javascript :: Mapping an Array to Elements with v-for 
Javascript :: online js to typescript converter 
Javascript :: Copy an Array with the Spread Operator 
Javascript :: filebase64 template 
Javascript :: nestjs optional guard 
Javascript :: mcrypt_rand rewrite in node js 
Javascript :: scriptcase javascript close modal form 
Javascript :: check if element is displayed 
Javascript :: cookies in electron 
Javascript :: nodejs how to beautify mysql arrays 
Javascript :: angular pipe to capitalize all letters 
Javascript :: Backbon events In View 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =