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

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

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 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!