0

So i just copy&pasted the code from w3schools "Toggle Hide and Show"

<script>
    function myFunction() {
  var x = document.getElementById("myDIV");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}
</script>

and

<button onclick="myFunction()">Tutorial</button>
<div id="myDIV">
    <p>Rules blablablabla.</p>
</div>

really simple code but i'm not good with javascript, i want the div to be hidden at start and then when i click the button, it shows the div. Sorry for a such an amateur question and thanks !

wolfman
  • 1
  • 2
  • 1
    You just need to throw a `style="display: none;"` on the div element so it starts out hidden. Or make a CSS rule: `#myDIV { display: none; }` – Taplar Mar 03 '20 at 18:49

1 Answers1

0

Hello and welcome to stackoverflow!

If you want your code to be hidden at first, add style="display:none;" to your HTML code. This puts CSS styling on your HTML element.

It would look something like this

<button onclick="myFunction()">Tutorial</button>
<div id="myDIV" style="display:none">
    <p>Rules blablablabla.</p>
</div>

Hope this helps!

Lorik
  • 438
  • 2
  • 9
  • Thanks! But i have another problem, i have a while cycle with " and and a bit further i have an if cycle, with but when i click the button in the website it only shows it for like a half a second, then closes, each time i click on it. Would you know how to fix that ? – wolfman Mar 20 '20 at 15:07