Delete more than one row from table in Javascript
Account Home | Help | Blog | Contact us | Log Out

Welcome to Kbytes > Articles

Delete more than one row from table in Javascript

Posted By: siteadmin on 25/01/2015 00:35:00

If you are struggling to delete rows from a table in Javascript that match a certain criteria, then check that you are deleting "backwards", that is from the bottom of the table back.  This is because the row index will change each time you do a delete.
var table = document.getElementById('displayTable').getElementsByTagName('tbody')[0];
var tablelength = table.rows.length; 
 for(var i = tablelength -1 ; i >= 0;i--)   //this is the key - if you iterate forward the row numbers will be out of line.
 if ( table.rows[i].cells[ctUpdateFlag].innerHTML == 'PD') {   //or whatever criteria you have here PD means PENDING DELETE from another process.

blog comments powered by Disqus

Kbytes Home | Privacy Policy | Contact us | Testing Area

© 2004 - 2024 1 Oak Hill Grove Surbiton Surrey KT6 6DS Phone: +44(020) 8123 1321