JavaScript Kit > DOM Reference > Here
Table Object Methods
The Table object of the DOM supports a handful of unique properties and methods to help you easily perform tasks like dynamically generate a table or certain rows/columns. This is on top of the standard DOM Element properties/ methods the Table object has access to.
Table object methods
Methods | Description | ||||
---|---|---|---|---|---|
createCaption() | Creates an empty table caption (until you populate
it with text), or if a caption already exists for this table,
references that caption. Example(s): var mytable=document.getElementById("atable")
|
||||
createTFoot() | Creates an empty table tfoot (until you populate it
with rows via tfoot.insertRow()), or if a tfoot already exists for
this table, references that tfoot. Example(s): var mytable=document.getElementById("atable") |
||||
createTHead() | Creates an empty table thead (until you populate it with rows via thead.insertRow()), or if a thead already exists for this table, references that thead. | ||||
deleteCaption() | Deletes the caption of the table. | ||||
deleteRow(index) | Deletes a row (tr) as specified by the "index"
parameter, an integer denoting the position of the row to delete
within the rows[] collection. Example(s): var mytable=document.getElementById("atable") |
||||
deleteTFoot() | Deletes the tfoot of the table. | ||||
deleteTHead() | Deletes the thead of the table. | ||||
InsertRow(index) | Inserts a new (empty) row to the table as specified
by the "index" parameter, an integer denoting the position of the
new row within the rows[] collection. You should then use
tr.insertCell() to insert new cells into the row. Returns a
reference to the new row. You can specify that the new row be added to the very end of the table by passing in -1 as the "index" parameter value. Example(s): var mytable=document.getElementById("atable") produces something like:
|
||||
moveRow(fromIndex, toIndex) | IE5+ exclusive method that moves a row from
its original location to another row location. The first parameter
denotes the row you wish to move based on its index position in the
rows[] collection, while the 2nd parameter denotes the index
position to move the row to. Returns a reference to the moved row. Example(s): var mytable=document.getElementById("atable") |
Table tr object methods
The tr element of a table supports additional DOM methods of its own, namely, for the creation of table cells within it. Here they are:
Methods | Description |
---|---|
deleteCell(index) | Deletes a td or th element from a tr based on its position within the row's cell[] collection, where index is an integer denoting that position. |
insertCell(index) | Inserts a new (empty) cell to the row as specified
by the "index" parameter, an integer denoting the position of the
new cell within the row's cell[] collection. You can specify that the new cell be added to the very end of the row by passing in -1 as the "index" parameter value. Example(s): var mytable=document.getElementById("atable") |
DD CSS Library
Free CSS menus and codes to give your site a visual boost.