📌  相关文章
📜  如何从 DOM 中删除所有类,然后添加数组的所有元素 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:47.588000             🧑  作者: Mango

代码示例1
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{
    console.log(myArray);
    myArray[index].removeAttribute('class');
    myArray[index].classList.add(select);
  });
  
  for(var ii=0; ii{
      myArray[ii].classList.add(item);
    });
  }  
}