-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent_test.html
More file actions
28 lines (26 loc) · 992 Bytes
/
Copy pathevent_test.html
File metadata and controls
28 lines (26 loc) · 992 Bytes
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
<!DOCTYPE html>
<html lang="kr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>event 연습</title>
</head>
<body>
<button class="btn1">gray</button>
<div class="menu">메뉴바</div>
<button class="btn2">pink</button>
<script>
let btn1 = document.querySelector(".btn1");
let btn2 = document.querySelector(".btn2");
let menu = document.querySelector(".menu");
btn1.addEventListener("mouseover",changecolor);
btn1.onmouseout = () => {menu.style.backgroundColor="transparent";}
btn2.onclick = () => {menu.style.backgroundColor="pink";}
// 선언적 함수는 hoisting이 일어나는 관계로 사용을 지양하자.
// hoisting이란 함수가 만들어지기 전인 최상의 scope로 끌어올려진 상태
function changecolor() {
menu.style.backgroundColor="gray";
}
</script>
</body>
</html>