통합검색

Javascript

[javascript] toggle 이벤트

  • 2023.12.06 17:25:14
[!]javascript[/!]
 
var btn_tog = document.getElementById("btn2");

btn_tog.addEventListener('click', () => { text_tog(); });

function text_tog(){
    btn_tog.classList.toggle("on");

    if(btn_tog.classList.contains("on")){
        btn_tog.innerText = "처리중";
    }else{
        btn_tog.innerText = "완료";
    }
}



[!]결과 화면[/!]

sample site 바로가기