<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Momentum App</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div id="first" class="Momentum">
        <h1>Grab me!</h1>
    </div>
    <script src="app.js"></script>
</body>
</html>
JS
const title = document.querySelector(".Momentum h1");
const handleMouseEnter = () => {
    title.innerText = "Mouse is here!";
}
const handleClickEvent = () => {
    title.style.color = "red";
}
const handleOnMouse = () => {
    title.innerText = "Mouse is gon!";
}
title.addEventListener("mouseenter", handleMouseEnter);
title.addEventListener("click", handleClickEvent);
title.addEventListener("mouseleave", handleOnMouse);
결과:

- click
 
- 사용자의 클릭을 감지하여 두번째 인자인 함수를 실행한다.
 - 위 코드에서는 클릭하여 HTML 요소의 스타일인 색상을 변경.
 
- mouseenter
 
- 사용자가 HTML 요소에 마우스가 들어갔을때 함수를 실행한다.
 - 위 코드에서는 텍스트를 변경하고 있다.
 
- mouseleave
 
- 사용자가 HTML 요소위에 마우스를 둔 상태에서 요소 밖으로 빠져 나왔을때 함수를 실행한다.
 - 위 코드에서는 텍스트를 변경하고 있다.
 
JS
const title = document.querySelector(".className div");
const handleClick = () => {
	title.innerText = "Hello!";
}
title.addEventListener("click, handleClick");
===
title.onclick = handleClick;
addEventListener 구문과 onclick 구문은 기능적으로 완전히 일치한다.
document가 JavaScript에서 기본적으로 제공되듯이 window도 기본으로 제공하는 객체 아마도 여기에 포함된 메서드를 사용할듯
- resize
 
<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Momentum App</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div id="first" class="Momentum">
        <h1>Grab me!</h1>
    </div>
    <script src="app.js"></script>
</body>
</html>
JS
const handleWindowResize = () => {
    document.body.style.backgroundColor = "tomato";
}
window.addEventListener("resize", handleWindowResize);
결과:

- clipboard events(copy, cut, paste)
 
const handleWindowCopy = () => {
    alert("Copy this");
}
window.addEventListener("copy", handleWindowCopy);
결과:

- connect Event(online, offline)
 
JS
const handleWindowOnline = () => {
    alert("Wifi on");
}
const handleWindowOffline = () => {
    alert("Wifi off");
}
window.addEventListener("online", handleWindowOnline);
window.addEventListener("offline", handleWindowOffline);
결과:


HTML
<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Momentum App</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div id="first" class="container">
        <h1>Click me!</h1>
    </div>
    <script src="app.js"></script>
</body>
</html>
JS
const CilckText = document.querySelector(".container h1");
const handleClick = () => {
    if(CilckText.style.color === "red") {
        CilckText.style.color = "blue";
    } else {
        CilckText.style.color = "red";
    }
}
CilckText.addEventListener("click", handleClick);
JS의 중복을 제거해본다
JS
const clickText = document.querySelector(".contaniner h1");
const handleClick = () => {
	const currentColor = clickText.style.color
    let changedColor
    if (currentColor === "red") {
    	changedColor = "blue"
    } else {
    	changedColor = "red"
    }
    clickText.style.color = changedColor
}
clickText.addEventListener("click", handleClick);
결과:
Click me! 를 클릭 할때 초기 색상은 black이다 그러면 else 구문에 changedColor에 red가 할당되고 clickText.style.color = red가 되어 함수는 종료된다.
다시 click me!를 클릭하면 색상은 red이므로 첫번째 if구문의 코드가 실행되어 changedColor에 blue가 할당되고 clickText.style.color = blue가 되어 함수는 종료된다.