Magum Opus

div.onclick = function(){
if ( this.getAttribute("class").indexOf("image-selected") == -1){
this.setAttribute("class","image image-selected")
}else{
this.removeAttribute("class","image image-selected")
}
// 위의 if문은 아래 .toggle() 로 줄일 수 있다
this.classList.toggle("image-selected")
}


' > javascript' 카테고리의 다른 글

모솔 몇일차인지 구하기....  (0) 2018.01.03
띠 구하기  (0) 2018.01.03
2017.11.29  (0) 2017.11.29