Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda