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

102
Views
Vanilla JS Accordion

Given the code below, how can I add functionality that hides active items when clicking on another? I'd like only one item to be open at a time.

const toggleElements = document.querySelectorAll('.accordion__item');

toggleElements.forEach(el => {
  el.addEventListener('click', function() {
    this.classList.toggle('is-active');
  });
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Close all others, then open current.

const toggleElements = document.querySelectorAll('.accordion__item');

toggleElements.forEach(el => {
  el.addEventListener('click', function() {
    toggleElements.forEach(el => el.classList.remove('is-active'));
    this.classList.add('is-active');
  });
});
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!