Toggle between hiding and showing an element with JavaScript.
<button onclick="myFunction()">Click Me</button>
<div id="myDIV">
This is my DIV element.
</div>
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
Try it Yourself »
Tip: For more information about Display and Visibility, read our CSS Display Tutorial.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!