Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

99
Vistas
how i can use toggle and function that remove the class from the previous element together only using JavaScript i have tried to Different ways?

-First Way-

Here I Can't Remove The Previous Elements and add the class for The new One

linksBtnArr.forEach((item, index) => {
  item.addEventListener("click", () => {
    arrowArr[index].classList.toggle("active");
    if (arrowArr[index].classList.contains("active")) {
      menuArr[index].style.display = "block";
    } else {
      menuArr[index].style.display = "none";
    }
  });
}); 

-Second Way-

Here I Can remove The previous Element But i Can't use Toggle to Remove The class Form The Same Element That i clicked again

linksBtnArr.forEach((link, i) => {
  link.addEventListener("click", () => {
    removeActiveClasses();
    arrowArr[i].classList.add("active");
  });
});
// Remove The previous Menu
function removeActiveClasses() {
  arrowArr.forEach((arrow) => {
    arrow.classList.remove("active");
  });
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

this way

linksBtnArr.forEach( (lk,_,All_lk) => {
  lk.onclick =_=> {
    if (lk.classList.toggle('active'))
      All_lk.forEach( lx=> lx.classList.toggle('active', lk===lx) )
  } })
about 4 years ago · Juan Pablo Isaza Denunciar

0

Look At The UL Links That what i'm trying to Do ! https://mohmostafa-web.github.io/blogr-landing-page-frontend-mentor

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda