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

171
Views
Ocultar y mostrar div con botón

Chicos, estoy intentando algo para mi carpeta, pero estoy atascado y mi cerebro no puede entender lo que se supone que debo hacer, ¿pueden ayudarme, por favor?

Así que tengo una sección div que estoy ocultando, luego, con un BOTÓN (Más), se supone que debe mostrar el div, y el BOTÓN (Más) debería cambiar a BOTÓN (MENOS). Y realmente quiero que funcione de la forma en que lo estoy haciendo porque sé que puede funcionar, pero no estoy muy seguro de cómo hacerlo. ingrese la descripción de la imagen aquí

ingrese la descripción de la imagen aquí

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

0

Puede usar HTMLelement.addEventListener para manejar el evento de clic de botón y ocultar o mostrar el div apropiadamente usando la propiedad element.style.display , el siguiente código demuestra cómo funciona

 const divE = document.getElementById('more'); const btn = document.getElementById('show'); handler = () => { if (divE.style.display != 'none') { // if the element is not hidden, hide the element and change button text to "more" btn.innerHTML = 'More'; divE.style.display = 'none'; } else { // if the element is hidden, show the element and change button text to "less" btn.innerHTML = 'Less'; divE.style.display = 'block' } } btn.addEventListener('click', handler)
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <button id="show">Less</button> <div id="more"> IDk something here ig </div> </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!