JavaScript Reference/Javascript Methods/insertRow
"insertRow()" Example
<html>
<body>
<script language="JavaScript">
function function1() {
var myRow = document.all.myTable.insertRow();
var myCell = myRow.insertCell();
myCell.innerText = "The added cell";
}
</script>
<table id="myTable" border="1" cellspacing="5" cellpadding="5">
<tr>
<td width="100">3</td>
<td width="100">4</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
</table>
<button onclick="function1();">Add a cell</button>
</body>
</html>
"insertRow()" is applied to
Names noted with an asterisk (*) are JavaScript properties only.
+----------------+--------------------------------------------------------------+
| Applied_To |rows* <table> |
| |<tbody> <tfoot> |
| |<thead> |
+----------------+--------------------------------------------------------------+
"insertRow()" Syntax, Parameters and Note
Note:
Adds a row to the specified element.
Syntax:
document.elementID.rows.insertRow(param1)
document.getElementById("elementID").insertRow(param1)
document.all.elementID.insertRow(param1) // IE only
Parameters:
param1 Optional; the index.
The default value is -1, which appends the new row to the end.