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

292
Views
Read more or read less, needs to be clicked twice to work

I'm building a read more or lead less div with HTML and vanilla javascript. Everything works, but I have to click the button twice for some reasons to show the text, and from there it works great.

So the issue is, button needs to be clicked twice at first to show the content. From there it works great.

HTML File

<div id="test">
  <p>Hello World</p>
</div>

<button onclick="test()" id="testBtn">Read more</button>

On css file test is display:none

JS file

    var test = document.getElementById("test");
    var btnText = document.getElementById("testBtn");

    if (test.style.display !== "none") {
        btnText.innerHTML = "Read more"; 
        test.style.display = "none";
      } else {
        btnText.innerHTML = "Read less"; 
        test.style.display = "inline";
    }
}
about 4 years ago · Juan Pablo Isaza
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!