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

182
Visualizações
How to change the border style when click expand and collapse

I am creating a button where I want to click and expand, and get rid of the bottom border and when I expand it I want the bottom border to come back, so I create a function where when I click once, its modulo cannot divide by two and when I click one more time, which is collapse, the count for the button to click is 2 so it can be divided by 2. Below is my code but I don't know why it won't work.

<script>
 function hideBorder() {
      var count = 0;
      var btn = document.getElementById("chi");
      if (btn.onclick) {
        count++;
      }

      if (count % 2 == 0) {
        doucment.getElementById("chi").style.borderBottom = "2px solid #65daff";
        document.getElementById("chi").style.borderEndEndRadius = "10px";
        document.getElementById("chi").style.borderEndStartRadius = "10px";
      } else if (count % 2 == 1) {
        doucment.getElementById("chi").style.borderBottom = "none";
        document.getElementById("chi").style.borderEndEndRadius = "0px";
        document.getElementById("chi").style.borderEndStartRadius = "0px";
      }
    }
</script>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

having the count variable inside the function means everytime the function is being called, count's value resets to 0. fixing it is as simple as moving the declaration of count outside of the function, making it "global".

about 4 years ago · Juan Pablo Isaza Relatório

0

var count = 0;
function hideBorder() {
  var btn = document.getElementById("chi");
  if (btn.onclick) {
    count++;
  }
  if (count % 2 == 0) {
    btn.style.borderBottom = "2px solid #65daff";
    btn.style.borderEndEndRadius = "10px";
    btn.style.borderEndStartRadius = "10px";
  } else if (count % 2 == 1) {
    btn.style.borderBottom = "none";
    btn.style.borderEndEndRadius = "0px";
    btn.style.borderEndStartRadius = "0px";
  }
}
<button id="chi" onclick="hideBorder()">click</button>

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