<body>
<div id="first">This is the FIRST div</div>
<div id="second">This is the SECOND div</div>
<div id="third">This is the THIRD div</div>
<button id="toggle">Hide THIRD div</button>
<script>
const targetDiv = document.getElementById("third");
const btn = document.getElementById("toggle");
btn.onclick = function () {
if (targetDiv.style.display !== "none") {
targetDiv.style.display = "none";
} else {
targetDiv.style.display = "block";
}
};
</script>
</body>
<button onclick="toggleDiv()">Toggle Div</button>
<div id="myDIV" class="hidden">
This is my DIV content.
</div>
<style>
.hidden {
display: none;
}
</style>
<script>
function toggleDiv(){
document.querySelector('#myDIV').classList.toggle('hidden');
}
</script>