티스토리 뷰

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 |