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

194
Views
No se puede recorrer la tabla en javascript

Soy nuevo en javascript y actualmente estoy tratando de recorrer las filas de la tabla para obtener los datos, sin embargo, muestra un error que no puede reconocer las rows de la table .

 <div class="row" id="tablediv"> <div class="col"> <table class="table table-striped table-bordered" id="table"/> </div> </div>
 var table = document.getElementById('#table'); for (let i in table.rows) { let row = table.rows[i]; //iterate through rows //rows would be accessed using the "row" variable assigned in the for loop console.log(row); for (let j in row.cells) { let col = row.cells[j]; //iterate through columns //columns would be accessed using the "col" variable assigned in the for loop console.log(col); } }
 offices:1048 Uncaught TypeError: Cannot read properties of null (reading 'rows') at save (offices:1048:25) at HTMLButtonElement.onclick (offices:101:84)

¿Estoy haciendo algo mal o hay una solución para eso?

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

0

Su variable de tabla debe declararse antes. Puedes hacerlo :

 <table id="myTab1"> <thead> <tr> <th scope="col">First</th> <th scope="col">Last</th> <th scope="col">Handle</th> </tr> </thead> <tbody> <tr class="rowTable"> <td>Mark</td> <td>Otto</td> <td>@mdo</td> </tr> <tr class="rowTable"> <td>Jacob</td> <td>Thornton</td> <td>@fat</td> </tr> <tr class="rowTable"> <td>Larry</td> <td>the Bird</td> <td>@twitter</td> </tr> </tbody> </table> <script> var table = document.getElementById("myTab1"); for (let i = 0; i < table.rows.length; i++) { let row = table.rows[i] for (let j = 0; j < row.cells.length; j++) { let cell = row.cells[j]; console.log(cell.textContent) } }
about 4 years ago · Juan Pablo Isaza Report

0

Tienes que apuntar a la mesa primero. Con var table = document.getElementById("myTable"); , puede almacenar en una tabla de variables y luego recorrerla.

En su ejemplo, esto se vería como var table = document.getElementById("table");

También verifique esto ¿Cómo itero a través de las filas y celdas de la tabla en JavaScript?

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!