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

74
Views
multiple dropdowns caret up and down onclick - vanilla javascript

I have multiple dropdowns that I want when clicking on one dropdown its caret be up instead of down and all its dropdowns siblings caret be down

<div>
<div><i class="fa-solid fa-caret-down toggle"></i></div>
<div><i class="fa-solid fa-caret-down toggle"></i></div>
<div><i class="fa-solid fa-caret-down toggle"></i></div>
<div><i class="fa-solid fa-caret-down toggle"></i></div>
</div>

this is my code

//tabs arrows up-down classes
let toggleButton = document.querySelector('.small-tab-container');
let toggle = document.querySelector('.toggle');

function toggleCaret() {
  toggle.classList.toggle('fa-caret-down');
  toggle.classList.toggle('fa-caret-up');
}
toggleButton.addEventListener('click', toggleCaret, false);

of course this code working only on first caret because I didn't loop throw siblings. I need to know:

1- how to loop on them?

2- how to make one of the carets are up all other carets are down?

I need to achieve this using pure javascript

about 4 years ago · Juan Pablo Isaza
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!