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

228
Vistas
Why is element.classList working the first time, but not the second?

My initial state shows my log in page, with a <div class="needAccount">Need an account? Sign up here</div>point. The sign up page is hidden, using:

const signup = document.querySelector(".signup");
signup.classList.add("inactive");

css:

.active{
    display: block;
}

.inactive{
    display: none;
}

That all works, but as soon as I try to make an event so that when clicking the need account it hides the log in page and shows the signup page, it does hide the login page but wont show the signup page:

const login = document.querySelector(".login");   

needAccount.addEventListener("click", (e) =>{
        login.classList.add("inactive");
        signup.classList.add("active")
    })

(I've also tried signup.classList.remove("inactive"), and tried using both states at once). I did this kind of script before on a different html page and it worked perfectly fine, but I can't figure out why it isn't working here. Is there some kind of rule to it?

(ps. I would like to stick with this style if possible as I want to practice event handlers and classlists, I'm guessing it would just be more efficient to make it link to a new html page)

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

0

If I understand the problem correctly, you have two options:

  1. Remove the inactive class from the signup element (that would be enough to make it visible). you can optionally add the active class to it

  2. You update the active style from display: block to display: block !important; to give this one higher priority and overwrite the inactive style while the inactive class is still on the element (not recommended)

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