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

191
Visualizações
Can not read properties of addEventListener in Javascript

I am making a simple web app with three buttons ("Show Modal 1", "Show Modal 2 and Show Modal 3) I want that at the moment of click the buttons a addEventListener will print in console "Button Clicked" every time the buttons are clicked, But for some reason it gives me the follow error: "Uncaught TypeError: Cannot read properties of undefined (reading 'addEventListener')".

const btnsOpenModal = document.querySelectorAll('.show-modal');

for (var i = 0; i = btnsOpenModal.length; i++)
  btnsOpenModal[i].addEventListener("click", function() {
    console.log("Button clicked");
  });
<button class="show-modal">Show modal 1</button>
<button class="show-modal">Show modal 2</button>
<button class="show-modal">Show modal 3</button>

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

0

As the comment already points out, the syntax is wrong. You are making a comparison in your for loop ending condition. However you are using an assignment operator. Read more about the differences in assignment and comparison here.

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