-5

I have problem with my code. On click "show button", I want to hide the button and show "data". But the data is not appearing. What is the problem?

 function my() {
        var yy = document.getElementById("show");
        yy.style.display="none";
     
       var b = document.getElementById("data");
        b.style.display="block";
      
      
      
    }
    #hide{ display:none;}
     


    #show{ display:true;} 
     
     

    #data{ display: none;}
     


    <div id="data"> this i s some data </div>
    <input onclick="my()" type="button" id="show" value="show data">
    <input type="button" id="hide" value="hide data">
  
ChatGPT
  • 5,334
  • 12
  • 50
  • 69

1 Answers1

2

To toggle the div this is the code using Javascript.

document.getElementById("hide").onclick=function(){
  document.getElementById("data").style.display="none";
  }
document.getElementById("show").onclick=function(){
  document.getElementById("data").style.display="block";
  }
<div id="data"> this is some data </div>
<input type="button" id="show" value="show data">
<input type="button" id="hide" value="hide data">
shubham agrawal
  • 3,435
  • 6
  • 20
  • 31