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

0

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);
      });
    }  
}
Posted by: Guest on October-10-2021

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

Code answers related to "Javascript"

Browse Popular Code Answers by Language