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

226
Visualizações
Trying to toggle a form using querySelector and it just isn't budging

I was trying to toggle a modal for my register and login tabs on a website I'm working on, but the final part turning it from hidden to visible on the website I was using a little javascript to add an "active" class to the forms making it so they then appear and whatnot... help :)

code:

CSS:

.login-form{
color: white;
text-align: center;
position: absolute;
top: 20%;
left: 37.5%;
transform: transform(-50%,-50%);
background: black;
border-radius: 15px;
box-shadow: 3px 3px 10px 1px rgba(0, 0, 0, 2);
visibility: hidden;
transform: .2s;

}

.login-form.active{
top: 50%;
transition: .2s;
visibility: visible;

}

.container-fluid.active{
filter: blur(20px);
transition: .2s;
pointer-events: none;

}

HTML: Form -

<div class="login-form">
    <div class="form">
        <div class="closeBTN" onclick="loginToggle()">&times;</div>
        <div class="title">
            <h1>Login</h1>
        </div>
        <form action="loginConfig.php">
            <input type="email" placeholder="Email" required>
            <input type="password" placeholder="Password" required>
            <input type="submit" value="Login">
        </form>
    </div>
</div>

Navbar portion:

<div class="login">
                <ul>
                    <li onclick="registerToggle()">Registar-se</li>
                    <li onclick="loginToggle()">Login</li>
                </ul>
            </div>

JS:

  function loginToggle() {
        var container = document.querySelector('.container-fluid');
        container.classlist.add('active');
        var popup = document.querySelector('.login-form');
        popup.classlist.add('active');
    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

One of your problem is that you don't respect the camel case of Java Script. You have to use it as "classList" instead of "classlist".

Also you don't have any element having ".container-fluid" in your code so that will trigger an error as well. Consider removing that line and change from classlist to classList and give it a try:

  function loginToggle() {
        //var container = document.querySelector('.container-fluid');
        //container.classList.add('active');
        var popup = document.querySelector('.login-form');
        popup.classList.add('active');
    }
.login-form{
color: white;
text-align: center;
position: absolute;
top: 20%;
left: 37.5%;
transform: transform(-50%,-50%);
background: black;
border-radius: 15px;
box-shadow: 3px 3px 10px 1px rgba(0, 0, 0, 2);
display:none;
transform: .2s;
}

.login-form.active{
top: 50%;
transition: .2s;
visibility: visible;
}

.container-fluid.active{
filter: blur(20px);
transition: .2s;
pointer-events: none;
}
.active{
  display:block;
}
<div class="login-form">
    <div class="form">
        <div class="closeBTN" onclick="loginToggle()">&times;</div>
        <div class="title">
            <h1>Login</h1>
        </div>
        <form action="loginConfig.php">
            <input type="email" placeholder="Email" required>
            <input type="password" placeholder="Password" required>
            <input type="submit" value="Login">
        </form>
    </div>
</div>

<div class="login">
                <ul>
                    <li onclick="registerToggle()">Registar-se</li>
                    <li onclick="loginToggle()">Login</li>
                </ul>
</div>

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