티스토리 뷰

DOM과 조건문

const title = document.getElementById("title"); 
const BASE_COLOR = "red";
const OTHER_COLOR = "blue";
 
function handleClick(){
    const currentColor = title.style.color;
    if(currentColor === BASE_COLOR){
        title.style.color = OTHER_COLOR;
    } else {
        title.style.color = BASE_COLOR;
    }
    console.log(currentColor);
}
 
function init(){
    title.style.color = BASE_COLOR;
    title.addEventListener("click", handleClick); // 원할 때 handleClick 호출
}
init();

와이파이 껐다 키기 

function handleOffline(){
    console.log("test off");
}
 
function handleOnline(){
    console.log("test on");
}
 
function init(){
    window.addEventListener("offline", handleOffline);
    window.addEventListener("online", handleOnline);
}
init();

'노마드코더 > Vanilla JS' 카테고리의 다른 글

#2.1.1 More Function Fun  (0) 2021.08.28
#1-5-1 What are we learning  (0) 2021.08.28
#0-2 What are we building  (0) 2021.08.28
#0-1 Requirements  (0) 2021.08.28
#2-5 첫번째 조건문!! If, else, and, or  (0) 2021.08.28
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함