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

197
Views
TypeError no capturado: no se pueden leer las propiedades de una matriz indefinida (leyendo 'estilo') de li
var AddressesList = document.getElementsByTagName("li"); for (var i = 0; i < AddressesList.length; i++){ var allow = true; AddressesList[i].addEventListener("click", function() { if (allow == true) { AddressesList[i].style.backgroundColor = 'red'; allow = false; } }) }

Sigo recibiendo el error:

 Uncaught TypeError: Cannot read properties of undefined (reading 'style')

¿Tengo alguna idea de que hacer referencia a un elemento de matriz dentro del detector de eventos devuelve indefinido? Porque cuando intento simplemente imprimir el elemento de la matriz, no estoy definido, pero funciona fuera del detector de eventos. ¿Cuál es el problema y cómo lo soluciono?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Está funcionando de esta manera

 var AddressesList = document.getElementsByTagName("li"); for (let i = 0; i < AddressesList.length; i++) { const element = AddressesList[i]; var allow = true; element.addEventListener("click", function () { if (allow) { element.style.backgroundColor = "red"; allow = false; } }); }
 <!DOCTYPE html> <html> <head> <title>Parcel Sandbox</title> <meta charset="UTF-8" /> </head> <body> <div id="app"> <ul> <li>Inder</li> <li>Jane Doe</li> <li>John Doe</li> </ul> </div> <script src="src/index.js"></script> </body> </html>

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!