반응형
<!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">
<title>자바스크립트 이벤트</title>
<style>
a:link, a:visited {
color:black;
text-decoration: none;
}
ul {
list-style: none;
width:500px;
margin:10px auto;
padding:0;
}
li {
display:inline-block;
width:120px;
border:1px solid #ccc;
padding:10px 15px;
font-size:16px;
text-align:center;
}
#result {
width:500px;
height:300px;
margin:30px auto;
border:2px solid #ccc;
border-radius:15px;
}
p {
width:80%;
padding:10px;
line-height: 2em;
}
</style>
</head>
<body>
<ul>
<li><a href="#" onclick="backColor('green')">Green</a></li>
<li><a href="#" onclick="backColor('orange')">Orange</a></li>
<li><a href="#" onclick="backColor('purple')">Purple</a></li>
</ul>
<div id="result"></div>
</body>
</html>
<script>
function backColor(color) {
let result = document.querySelector("#result");
result.style.backgroundColor = color;
}
// }
</script>
반응형
'Java Script' 카테고리의 다른 글
[JS] DOM - getElementsByTagName (0) | 2023.04.12 |
---|---|
[JS] eventListener (0) | 2023.04.12 |
[JS] 초단위로 시간 변경 #setInterval (0) | 2023.04.12 |
[JS] 팝업 #window.open (0) | 2023.04.12 |
[JS] 배열 함수 (0) | 2023.04.11 |