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

243
Visualizações
What does this error mean and how to solve it?

There are tabs on the page when you click on which content opens. tabs were made on Bootstrap5 (this is what the customer wanted). But the problem is that the tabs are in different places.

Some in the header, others in the main and their windows should open in the middle of the page, and so that the top ones do not interfere with the bottom ones, you need to click on the top ones so that the class at the bottom ones is removed and vice versa.

Uncaught TypeError: Cannot read properties of undefined (reading 'classList') at HTMLAnchorElement. (file:///C:/Desktop/webLocale(application)/script.js:70:25)

It appears only when i tab on element with class ".nav-link"

const linkItem = document.querySelectorAll('.nav-item__link'),
  navLink = document.querySelectorAll('.nav-link'),
  tab = document.querySelectorAll('.tab-pane');

for (let i = 0; i < linkItem.length; i++) {
  linkItem[i].addEventListener('click', function(e) {
    e.preventDefault();
    for (let x = 0; x < linkItem.length; x++) {
      linkItem[x].classList.remove('active')
      navLink[x].classList.remove('active')

    }
    linkItem[i].classList.add('active')
  })
}

for (let a = 0; a < navLink.length; a++) {
  navLink[a].addEventListener('click', function(e) {
    e.preventDefault();
    for (let j = 0; j < navLink.length; j++) {
      linkItem[j].classList.remove('active') // error belong to this string
    }
    navLink[a].classList.add('active')
  })
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In line 4-6 you loop through navLink using a variable called j and then in line 5 you select item j from linkItem - it should probably be navLink.

1. for (let a = 0; a < navLink.length; a++) {
2.   navLink[a].addEventListener('click', function(e) {
3.    e.preventDefault();
4.    for (let j = 0; j < navLink.length; j++) {
5.      linkItem[j].classList.remove('active') // error belong to this string
6.    }
7.    navLink[a].classList.add('active')
8.  })
9. }

This could be an alternative to the places where you remove the class names instead of using a for-loop and confuse yourself:

navLink.forEach(link => link.classList.remove('active'));

And instead of navLink[a].classList.add('active') in line 7 write:

e.target.classList.add('active');
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