๐Ÿ“ƒ๋…ธ๋งˆ๋“œ์ฝ”๋” Vanilla JS ๋ฉ”๋ชจ1

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Momentum</title>
</head>
<body>
    <div class="hello">
        <h1>Grab me1</h1>
    </div>
    <div class="hello">
        <h1>Click me!</h1>
    </div>
    <div class="hello">
        <h1>Grab me3</h1>
    </div>
    
    <script src="app.js"></script>
</body>
</html>

CSS

@charset "UTF-8";

body{
    background-color: beige;
}

JS

const a = document.querySelector(".hello:nth-child(2)")
console.log(a.innerText);

function click(){
    a.style.color = "blue";
}

function over(){
    a.style.color = "red";
}

function title(){
    console.log("title was clicked!");
}

a.addEventListener("mouseover", click);
a.addEventListener("mouseout", over);
a.addEventListener("click", title);

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ