js show hide div code example
Example 1: javascript hide div
// javascript
<script>
document.getElementById("id").style.display = "none"; //hide
document.getElementById("id").style.display = "block"; //show
document.getElementById("id").style.display = ""; //show
</script>
// html
<html>
<div id="id" style="display:none">
<div id="id" style="display:block">
</html>
// jquery
<script>
$("#id").hide();
$("#id").show();
</script>
Example 2: how to hide div in html
document.getElementById('elementName').hide();
Example 3: javascript hide show div
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#hide").click(function(){
$("#1").hide();
$("#2").show();
});
$("#show").click(function(){
$("#1").show();
$("#2").hide();
});
});
</script>
</head>
<body>
<p id="1">Area 1</p>
<p id="2" style="display: none;">Second area</p>
<button id="show">Area 1</button>
<button id="hide">Second Area</button>
</body>
</html>
Example 4: javascript hide a div
<div id="main">
<p> Hide/show this div </p>
</div>
('#main').hide(); //to hide
// 2nd way, by injecting css using jquery
$("#main").css("display", "none");
Example 5: toggle element javascript
document.querySelector("#test").hidden = true;
document.querySelector("#test").hidden = false;