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

200
Views
the for loop exit after it has been executed one time

the for loop in the following code exit after removing one class and doesn't remove the other one unless I click the button again

I want to remove the class hidden from 2 divs but I don't want to use querySelectorAll.

is there any way to do it using getElementsByClassName and for loop, without JQuery Just JavaScript

I did the same thing before but it was to change the style of something not to add or remove classes.


var items = document.getElementsByClassName('hidden');

let show = document.querySelector('.show-modal');

show.addEventListener('click', function(){
    for (let i = 0; i < items.length; i++){
        items.item(i).classList.remove('hidden');  
    }
}); 

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

0

Using a forEach would help -

show.addEventListener('click', () => {
    items.forEach((element) => {
        element.classList.remove('hidden');  
    })
}); 
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!