el_box.className;el_box.classList;el_box.classList.add('bg_red');el_box.classList += 'bg_red'; add랑 +=랑 같아서 이렇게 써도 된다.el_box.classList = 'bg_red 이렇게 쓰게 되면 기존에 있던 클래스들을 다 bg_red로 덮게 되므로 주의할 것el_box.classList.add('bg_red', 'font'); 이렇게 쉼표로 구분해서 추가하면 됨el_box.classList += 'bg_red font'; 이렇게 따옴표 안에 띄어쓰기로 구분해서 넣으면 된다. el_box.classList.replace('bg_red', 'bg_blue');el_box.classList.remove('bg_green');el_box.classList.remove('bg_green', 'bg_blue');for(let i = 0; i < el_box.classList.length; i++){
el_box.classList.remove(el_box.classList[0]);
}el_box.className = ""; 이 한 줄이면 끝난다. el_box.classList.toggle('bg_red'); -> 현재 el_box에 bg_red 없으니까 삽입el_box.classList.toggle('bg_red'); -> 윗줄에서 넣고 왔으니까 있음. 그래서 삭제.let chk = true;
el_box.addEventListener('click', function(){
if(chk){
el_box.classList.add('bg_blue');
}else{
el_box.classList.remove('bg_blue');
}
chk = !chk;
});el_box.addEventListener('click', function(){
el_box.classList.toggle('bg_blue');
});el_box.classList.contains('bg_blue');