반응형
const title = document.querySelector("#title");
const BASE_COLOR = "red";
const OTHER_COLOR = "#7f8c8d";
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.addEventListener("mouseenter", handleClick);
}
init();
마우스를 올리면 색이 변경됨
mouseenter을 click 로 바꾸면 클릭시 색이 변경됨
반응형
'2020 > JAVA SCRIPT' 카테고리의 다른 글
spread연산자 (0) | 2020.03.28 |
---|---|
<noscript> (0) | 2020.01.29 |
<script> (0) | 2020.01.25 |