const title= document.querySelector("#title");
const BASE_COLOR = "#~ " ;
const OTHER_COLOR= "#~~" ;
function handleClick() {
const currentColor = title.style.color;
if(currentColor===BASE_COLOR){
title.style.color= OTHER_COLOR;}
else {title.style.color=BASE_COLOR;}}
function init() {
title.style.color=BASE_COLOR;
title.addEventListner("click->mouseenter", handleClick);
}
init();
ex)
function handleOffline(){
console.log("efefe");}
function handleOnline(){
console.log("welcome back ");}
window.addEventListner("offline", handleOffline);
window.addEventListner("offline", handleOnline);
//--> wifi 를 끄고 켤때마다 문구가 호출됨.
javascript dom MDN ->event 종류 어마어마하게 많이 있음.
const title= document.querySelector("#title");
const CLICKED_CLASS="clicked";
function handleClick(){
const hasClass=title.classList.contains(CLICKED_CLASS);
if(hasClass){
title.classList.remove(CLICKED_CLASS);}
else{ title.classList.add(CLICKED_CLASS);}
}
function init(){
title.addEventListener("click",handleClick);}
init();