Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!