Search
 
SCRIPT & CODE EXAMPLE
 

HTML

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>
Comment

PREVIOUS NEXT
Code Example
Html :: import google maps libraries html 
Html :: svg as button 
Html :: link to external site html 
Html :: git stash pop name 
Html :: ngfor display in html table 
Html :: colspan vertical 
Html :: write python code in html 
Html :: embed github html 
Html :: slick slider pause on video play 
Html :: How to align input line in html forms 
Html :: form example 
Html :: target vs currenttarget 
Html :: bootstrap form textarea 
Html :: html element hover helptext 
Html :: set text of file input 
Html :: html text content new line 
Html :: bootstrap 5 tab 
Html :: bootstrap country flag dropdown 
Html :: show google map in html 
Html :: how to convert html to text in angular 
Html :: html single line comment 
Html :: html5 select 
Html :: p tag html 
Html :: check if OS path exists through Python 
Html :: the use of span tag 
Html :: html auto change year 
Html :: The template root requires exactly one element.eslint-plugin-vue 
Html :: checkbox html style 
Html :: html button with href 
Html :: conditional script tag in html head site:stackoverflow.com 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =