통합검색

Javascript

[javascript] onclick 이벤트

  • 2023.12.06 17:24:43
[!]javascript[/!]
 
var ele_btn = document.getElementsByClassName("btn_cn")[0];
var ele_btn_qs = document.querySelector(".btn_qs");
var ele_btn_qsa = document.querySelector(".btn_qsa");
var ele_btn_reset = document.getElementById("btn_reset");

ele_btn.addEventListener('click', () => {
    ele_btn.innerText = ":::클릭했지롱~:::";
});

ele_btn_qs.addEventListener('click', () => {
    ele_btn_qs.innerText = ":::클릭했지롱~:::";
});

ele_btn_qsa.addEventListener('click', () => {
    ele_btn_qsa.innerText = ":::클릭했지롱~:::";
});

ele_btn_reset.addEventListener('click', () => {
    ele_btn.innerText = "버튼 클릭해줄래?";
    ele_btn_qs.innerText = "선택자 querySelector로 적용";
    ele_btn_qsa.innerText = "선택자 querySelectorAll로 적용";
});



[!]결과 화면[/!]

sample site 바로가기