Answers for "show div on click of button hide others"

2

onclick show div and hide other div

<div id="div1">A DIV element...</div>
<div id="div2">Another DIV element</div>
<div id="div3" hidden>A hidden DIV element</div>
<button id="switch">Click to hide visible DIVs and show hidden ones</button>
<script type="text/javascript">
	const div1 = document.getElementById("div1"),
		div2 = document.getElementById("div2"),
		div3 = document.getElementById("div3");
	document.getElementById("switch").addEventListener("click", function() {
		// hide element: element.hidden = true;
		// show element: element.hidden = false;
		div1.hidden = !div1.hidden;
		div2.hidden = !div2.hidden;
		div3.hidden = !div3.hidden;
	});
</script>
Posted by: Guest on September-01-2021
0

how to make a div disappear when another button i clicked

<html>
<head>
<title></title>
<script>
function myFunction() { 
	document.getElementById("mainFrameOne").style.display="none"; 
	document.getElementById("mainFrameTwo").style.display="block"; 
}
</script>
</head>
<body>
<div id="mainFrameOne">
    <p>mainFrameOne</p>
</div>
<div id="mainFrameTwo" style="display:none;">
    <p>mainFrameTwo</p>
</div>
<button onclick="myFunction()">Click me</button>
</body>
</html>
Posted by: Guest on August-13-2020

Code answers related to "show div on click of button hide others"

Browse Popular Code Answers by Language