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

108
Visualizações
How do I get all the elements instead of just the first one?

I am trying to get this accordion style faq-sheet to work. So far I can only seem to get the first element to show the hidden content. Here is my js:

var arrowIcon = document.querySelector('.arrow-icon');
var hidden = document.querySelector('.hidden');

var answer = 'answer';

arrowIcon.addEventListener('click', function() {
  if (answer === 'hidden') {
    answer = 'answer';
    hidden.setAttribute('class', 'answer');
  }
  else {
    answer = 'hidden';
    hidden.setAttribute('class', 'hidden');
  }
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to use querySelectorAll and then iterate through each element and add click listener. Keep in mind that querySelectorAll returns a nodeList not an array. So if you want to use all the array functionality make sure you convert it into array.

Something like this should work:

var arrowIcon = Array.from(document.querySelectorAll('.arrow-icon'));

arrowIcon.forEach(el => {
    el.addEventListener("click", => (event) {
        // Your Code Here
    })
});
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