Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
How to hide <div>

I'm making a prank .html page for a friend. The prank was, you would push a button and a phrase would pop up under the button. I figured out a way to hide the phrase and unhide it. The problem is that, when you load into the page, the phrase would already be on the screen. How do I keep it hidden on page load?

function Function() {
  var x = document.getElementById("urmom");
  
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}
<p>Click the "Try it" button to toggle between hiding and showing the DIV element:</p>

<button onclick="Function()">Try it</button>

<div id="urmom">
  ur mom
</div>

<p><b>Note:</b> The element will not take up any space when the display property set to "none".</p>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Set with CSS first as NONE.

function Function() {
  var x = document.getElementById("urmom");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">

</head>
<body>

<p>Click the "Try it" button to toggle between hiding and showing the DIV element:</p>

<button onclick="Function()">Try it</button>

<div id="urmom" style="display:none">
ur mom
</div>

<p><b>Note:</b> The element will not take up any space when the display property set to "none".</p>
 

</body>
</html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!