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

163
Views
Hide / Show toggle button doesn't start with content hidden

It works but it doesn't start off with my 'more details' content toggled to hidden. It starts off with the content showing. I have rewritten this 10 times and can't figure it out.

function toggle() {
  let Text = document.getElementById('moreDetails');

  if (Text.style.display == "none") {
    Text.style.display = "block";
  } else {
    Text.style.display = "none";
  }
}
<div id="moreDetails">

  <h3> 001 </h3>

  <h3> Saturate Radio </h3>

  <h4> N00DS </h4>

</div>

<button title="Click to Show" type="button" onclick="toggle()">MoreDetails</button>

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

0

add style display none to your div id moreDetails

<div id="moreDetails" style="display: none">

or you can use like this also

<script>
function toggle(){
    let Text = document.getElementById('moreDetails');

    if(Text.style.display == "none"){
        Text.style.display= "block";
    }
    else {
        Text.style.display = "none";
    }
}
document.getElementById("moreDetails").style.display = "none";
 
</script>

or you can use ternary operator

<script>
    function toggle(){
        const Text = document.getElementById('moreDetails');
        Text.style.display = Text.style.display == "none" ? "block" : "none";
    }
    document.getElementById("moreDetails").style.display = "none";
</script>
about 4 years ago · Juan Pablo Isaza Report

0

To start with more details hidden, you should add style="display: none;" to your div; Here's the code:

function toggle() {
  let Text = document.getElementById('moreDetails');

  if (Text.style.display == "none") {
Text.style.display = "block";
  } else {
Text.style.display = "none";
  }
}
<div id="moreDetails" style="display: none;">

  <h3> 001 </h3>

  <h3> Saturate Radio </h3>

  <h4> N00DS </h4>

</div>

<button title="Click to Show"  type="button" onclick="toggle()">MoreDetails</button>

about 4 years ago · Juan Pablo Isaza Report

0

Add display none for div.

function toggle(){
    const Text = document.getElementById('moreDetails');
    Text.style.display = Text.style.display == "none" ? "block" : "none";
}
<div id="moreDetails" style="display: none">

  <h3> 001 </h3>

  <h3> Saturate Radio </h3>

  <h4> N00DS </h4>

</div>

<button title="Click to Show" type="button" onclick="toggle()">MoreDetails</button>

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!