Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to remove all Class(es) from a DOM, and then adds all Elements of an Array

function changeCSS(select, cssArray){
  //function that Removes all Class(es) from a 'queried DOM'
  //then adds back to that DOM element, all the entries from the 2nd parameter Array
  // 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 :: node fs stream pipe promise 
Javascript :: create 24 hours array like 00:00 to 23:30 
Javascript :: js detect where function call came from 
Javascript :: alpinejs checknox selectAll 
Javascript :: react native image path in vriable 
Javascript :: how to bind multiple value in javascript 
Javascript :: change frame rate javascript 
Javascript :: React svg element rating 
Javascript :: how concatenate arrays in es6 
Javascript :: refresh mathjax 
Javascript :: remove image Input of element 
Javascript :: js find :invalid inside div 
Javascript :: Make JSON grep-able via GRON 
Javascript :: npm package al dar una direccion se obtienen las coordenadas longitud y latitud 
Javascript :: string in vue.js 
Javascript :: solana solana-Web3.js change for devnet lamports to production transaction 
Javascript :: formatDuration js 
Javascript :: how to square a number in html 
Javascript :: early exit js 
Javascript :: ubicar escrol en el final js 
Javascript :: react-native-calendars how to mark selected day 
Javascript :: editable pre input react 
Javascript :: pure-javascript-listen-to-input-value-change 
Javascript :: load json object from file frontend javascript 
Javascript :: aws lambda create 
Javascript :: Function Recurser / Infinit Calling 
Javascript :: react proxy to flask server 
Javascript :: three.js first issue resolved awwwards merge webgl html worlds 
Javascript :: make a table of data from db in jsp 
Javascript :: How to make a json call to a URL 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =