Notice
Recent Posts
Recent Comments
Link
«   2024/11   »
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 29 30
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter12 : DOM_문제 본문

WEB.JS/08.DOM_JS

chapter12 : DOM_문제

GAWON 2023. 5. 22. 09:29
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function viewAnswer(){
//정답이 숨겨져 있으면 ->정답 숨기기로 변경,style visibility:visible로 변경
var answer = document.getElementById("#answer");
var btn = document.getElementById("#btn");
if(btn.innerHTML == '정답보기'){
btn.innerHTML = "정답숨기기";
answer.style.visibility = "visible";
}else{
btn.innerHTML = '정답보기';
answer.style.visibility = "hidden";
}
}

</script>
</head>
<body>
<h3>다음 중 없는 태그는?</h3>
<div>
<ol>
<li>p</li>
<li>a</li>
<li>br</li>
<li>am</li>
</ol>
</div>
정답보기 : [<span id = "answer" style="visibility: hidden;">4</span>]  
<button id="btn" onclick="viewAnswer();">정답 숨기기</button>
</body>
</html>

'WEB.JS > 08.DOM_JS' 카테고리의 다른 글

chapter07 : DOM_getElementsByTagName  (0) 2023.05.22
chapter08 : DOM_getElementsByClassName  (0) 2023.05.22
chapter09 : DOM_querySelector  (0) 2023.05.22
chapter10 : DOM_style  (0) 2023.05.22
chapter11 : DOM_문제  (0) 2023.05.22