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

172
Vistas
Hide and Show Div with button

guys, I'm trying something for my portfolio but I'm stuck and my brain just can't understand what I'm supposed to do can you guys please help?

So I have a div section that I'm hiding, then with a BUTTON(More) click it is supposed to show the div, and the BUTTON(More) should change to BUTTON(LESS). And I really want to make it work the way I'm doing it because I know it can work I'm just not too sure how. enter image description here

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use HTMLelement.addEventListener to handle button click event and hide or show the div appropriately using the element.style.display property, the code below demonstrates how it works

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 Denunciar
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