How to display div caused by onclick event

I have two div s. I want to show a div (which has a different div inside it) when the onclick event fires.

Any help or suggestion would be appreciated.

Mockup of a div containing a submit button and another div

+4
source share
4 answers

Here you go:

 div{ display: none; } document.querySelector("button").addEventListener("click", function(){ document.querySelector("div").style.display = "block"; }); <div>blah blah blah</div> <button>Show</button> 

LIVE DEMO: http://jsfiddle.net/DerekL/p78Qq/

+11
source

You need to provide the div id you want to show / hide and then use this code:

HTML:

 <div id="one"> <div id="tow"> This is text </div> <button onclick="javascript:showDiv();">Click to show div</button> </div> 

JavaScript:

 function showDiv() { div = document.getElementById('tow'); div.style.display = "block"; } 

CSS

 #tow { display: none; }​ 

Fiddle: http://jsfiddle.net/xkdNa/

+9
source

If you have a div id try the following:

  <input type='submit' onclick='$("#div_id").show()'> 
+3
source
 function showstuff(boxid){ document.getElementById(boxid).style.visibility="visible"; } 
 <button onclick="showstuff('id_to_show');" /> 

It will help you, I think.

+3
source

Source: https://habr.com/ru/post/1415684/


All Articles