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

451
Views
Cómo eliminar filas de tablas usando javascript

Quiero eliminar todas las filas de la tabla usando javascirpt Aquí está el código que probé usando la función .remove pero no funcionó...

CÓDIGO DE TABLA HTML

 <div class="card-body"> <table class="table text-center"> <thead> <tr> <th scope="col">#</th> <th scope="col">Name</th> <th scope="col">Total</th> <th scope="col">Reaming Paid</th> <th scope="col">To Be Paid</th> </tr> </thead> <tbody id="table_body"> <tr> <td>2</td> <td> mess fee </td> <td> 2500 </td> <td>0 </td> <td> <input type="number" id="remaing_amount" name="remaing_amount[]" class="form-control" placeholder="Enter Paid Amount"></td> </tr> </tbody> </table> </div>

CÓDIGO JAVASCRIPT

 if(tablebody.children.length > 0) { for (let i = 0; i < tablebody.children.length; i++) { tablebody.children[i].remove() } }
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Explicación

Esto obtendrá todas las tr (filas) para el cuerpo de las tablas. Luego eliminará (eliminará) cualquiera que encuentre

Solución

 let trs = document.querySelectorAll('#table_body tr'); trs.forEach((tr)=>{ tr.remove(); });
about 4 years ago · Juan Pablo Isaza Report

0

Encuentre todas las filas de la tabla, itere sobre ellas usando for of y luego elimine cada fila con Element.remove() .

 const rows = document.querySelectorAll("#table_body tr"); for (const row of rows) { row.remove(); }
 <div class="card-body"> <table class="table text-center"> <thead> <tr> <th scope="col">#</th> <th scope="col">Name</th> <th scope="col">Total</th> <th scope="col">Reaming Paid</th> <th scope="col">To Be Paid</th> </tr> </thead> <tbody id="table_body"> <tr> <td>2</td> <td>mess fee</td> <td>2500</td> <td>0</td> <td> <input type="number" id="remaing_amount" name="remaing_amount[]" class="form-control" placeholder="Enter Paid Amount" /> </td> </tr> </tbody> </table> </div>

about 4 years ago · Juan Pablo Isaza Report

0

Si desea eliminar todos los tr, tal vez debería hacer algo como esto

 document.getElementById('table_body').innerHTML = ''
 <div class="card-body"> <table class="table text-center"> <thead> <tr> <th scope="col">#</th> <th scope="col">Name</th> <th scope="col">Total</th> <th scope="col">Reaming Paid</th> <th scope="col">To Be Paid</th> </tr> </thead> <tbody id="table_body"> <tr> <td>2</td> <td> mess fee </td> <td> 2500 </td> <td>0 </td> <td> <input type="number" id="remaing_amount" name="remaing_amount[]" class="form-control" placeholder="Enter Paid Amount"></td> </tr> </tbody> </table> </div>

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!