insertRow method (Internet Explorer)

Switch View :
ScriptFree
insertRow method

[This documentation is preliminary and is subject to change.]

Creates a new row (tr) in the table, and adds the row to the rows collection.

Document Object Model (DOM) Level 2 HTML Specification, Section 1.6.5

Syntax

object.insertRow(index)

Standards information

Parameters

index [in, optional]

Type: long

Integer that specifies where to insert the row in the rows collection. The default value is -1, which appends the new row to the end of the rows collection.

Return value

Type: ObjectReturns the tr element object if successful, or null otherwise.

Remarks

The preferred technique for inserting a row is to add the row at the end of the rows collection. It is faster to add a row at the end of a table than somewhere in the middle. To add a row at the end of the collection, specify the -1 value, or the length of the rows collection minus 1.

Examples

This example uses the insertRow method to add a row to the table.


myNewRow = document.all.myTable.insertRow()

See also

table
tBody
tFoot
tHead
Reference
rowIndex
rows
sectionRowIndex

 

 

Build date: 3/8/2012

Community Content

damascustech
Documentation is slightly wrong
This line...  "To add a row at the end of the collection, specify the -1 value, or the length of the rows collection minus 1."  ...is slightly wrong.  That last "minus 1" should be removed.  If you use (length - 1) as the index, it will add a row before the last row.  You want to specify the full length of the rows collection.  So if there are 2 rows and you want to add one to the end, you should call insertRow(2).  Or just use -1.

Rich OBrien
This DOES work, as documented.

This DOES work, as documented.

  newRow = RegisterTable.insertRow();

  newRow.onClick = "RegisterTableData.onclick()";

  for(var j = 0; j <= xXRRec1.length -1; j++){

   newCell = newRow.insertCell();



etc ... etc


Thomas Lee
no way to add row
Contrary to what the documentation suggests, there is no way to add an existing row to the rows collection.