방법 - 숨기기 및 표시 전환
JavaScript를 사용하여 요소 숨기기와 표시 사이를 전환합니다.
버튼을 클릭하세요!
요소 토글(숨기기/표시)
1단계) HTML 추가:
예시
<button onclick="myFunction()">Click Me</button>
<div id="myDIV">
This is my DIV element.
</div>
2단계) 자바스크립트 추가:
예시
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display
=== "none") {
x.style.display = "block";
} else {
x.style.display =
"none";
}
}
팁: 디스플레이 및 가시성에 대한 자세한 내용은 CSS 디스플레이 튜토리얼 을 참조 하십시오.