Handling Tables in DOM
Handling Tables in DOM
1. Introduction
Tables are widely used in HTML to display structured data. The Document Object Model (DOM) provides
a set of methods and properties that allow developers to create, modify, and remove rows, columns,
and cells dynamically using JavaScript.
2. Accessing a Table
To work with a table in the DOM, you must first access it:
cell1.innerHTML = "Name";
cell2.innerHTML = "Age";
A. Delete a Row
B. Delete a Cell
<th>Name</th>
<th>Age</th>
</tr>
</table>
<script>
function addRow() {
cell2.innerHTML = "30";
</script>
row.style.backgroundColor = "lightgray";
cell1.setAttribute("align", "center");
9. Conclusion
DOM manipulation provides full control over HTML tables, enabling developers to dynamically add,
edit, or delete rows and cells. It’s an essential technique for building modern, interactive web
applications and handling data-rich interfaces efficiently.