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

179
Views
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 answers
Answer question

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 Report
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!