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

171
Visualizações
Toggling inline css statements in javascript

Forgive for a moment that there are vastly better ways to handle a simple toggle like this and pretend that we have to do it by declaring inline styles.

What's wrong with my logic such that I can't call toggleSidebar(); every time a button a clicked and always produce the opposite result of what is currently true? (This only works the first time you click the button right now).

function toggleSidebar() {
    var sidebar = document.getElementById('sidebar');
    var show = Boolean;
    
    if (show == null) {
        show = true;
    }

    if (show) { 
        sidebar.style.right = '0px';
        show = !show;
    } else {    
        sidebar.style.right = '-400px';
        show = !show;
    }
}
about 4 years ago · Juan Pablo Isaza
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