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

205
Visualizações
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 Respostas
Responde à pergunta

0

Using a forEach would help -

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