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

109
Views
forloop div event listeners not adding/removing classes
if (div.id === 'firstDiv')
            {
                div.addEventListener('click', function() {
                        div.classList.remove('w-1/4')
                        div.classList.add('w-full')
                })
            }

I have this code block in a for loop, it checks the id of each div in the loop, and adds an event listener to it. However, while the event listener works if I console.log it, it doesn't actually do anything with the classList

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The id of div is unique to every div so it just work in one div and you didn't defined which div should be change in the classlist so specify it with "this" keyword

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!