Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

299
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda