1. Computing & Technology

javascript, example code

DOM Table: 8. Deleting A Column

From , former About.com Guide

The way that tables are defined in HTML there is no wrapper around a column in the table that we can delete in order to delete the entire column the way we can with a row. In order to actually delete a column from a table we therefore need to delete all of the cells in a specific position within the table.

In this example we will loop through all the rows of the table (not just those in the tbody) and delete the second cell from each of those rows so as to effectively delete the entire second column from the table.


var tables;
tables = document.getElementsByTagName('table');
for (var i = tables[0].rows.length - 1; i >= 0; i--) {
  tables[0].rows[i].deleteCell(1);
}

Related Searches loop through tbody cells nbsp

©2012 About.com. All rights reserved.

A part of The New York Times Company.