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

232
Views
Cómo cerrar una lista desplegable cuando se abrió otra - Javascript

Soy un principiante :) y estoy tratando de cerrar una lista desplegable tan pronto como se seleccione otra. Aquí está lo que tengo hasta ahora y traté de incluir otro ciclo usando un forEach, pero debo hacer algo mal.

Me podría ayudar ?

Debajo del código simple en JS sin el segundo ciclo:

 const moreExperiences = document.querySelectorAll(".more"); /*moreExpS : [moreExp1, moreExp2, moreExp3, moreExp4]*/ moreExperiences.forEach(moreExperience => { moreExperience.addEventListener("click", () => { //split from - and take the second element after the - which will be the number (index 1) let elementId = moreExperience.id.split("-")[1]; let activeElId = `#detailsExp-${elementId}`; const activeElements = document.querySelector(activeElId) activeElements.classList.toggle("hide") activeElements.classList.toggle("visibleExp") //******write back see more + // change the text if (moreExperience.innerHTML === "SEE LESS -") { moreExperience.innerHTML = "SEE MORE +" } else { moreExperience.innerHTML = "SEE LESS -"} }); });

y aqui esta con el additioibn del 2nd loop

 moreExperiences.forEach(moreExperience => { moreExperience.addEventListener("click", () => { //split from - and take the second element after the - which will be the number (index 1) let elementId = moreExperience.id.split("-")[1]; let activeElId = `#detailsExp-${elementId}`; const activeElements = document.querySelector(activeElId) activeElements.classList.toggle("hide") activeElements.classList.toggle("visibleExp") //if another element is selected activeElements.forEach(activeElement => { if (activeElement.classList.has("visibleExp")) { activeElement.classList.remove("visibleExp") activeElement.classList.add("hide") } }); //******write back see more + // change the text if (moreExperience.innerHTML === "SEE LESS -") { moreExperience.innerHTML = "SEE MORE +" } else { moreExperience.innerHTML = "SEE LESS -"} }); });
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!