Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda