클릭한 메뉴 활성화 유지하기

summer_joy·2023년 1월 27일
0
const menu = document.querySelectorAll(".해당 class명");

     for(let i = 0; i < menu.length; i++) {
          menu[i].addEventListener("click", act);
          function act(){
               for(let j = 0; j < menu.length; j++){
                    menu[j].removeAttribute("class", "on"); // 추가하고자 하는 class명
               }
               this.setAttribute("class", "on");
          }
     }
profile
💻 Hello world

0개의 댓글