Which method is preferred for adding a row to a table?
var tr = tbl.insertRow(-1);
or
var tr = document.createElement('tr'); tbl.appendChild(tr);
?
Click in a cell above or below where you want to add a row. Under Table Tools, on the Layout tab, do one of the following: To add a row above the cell, click Insert Above in the Rows and Columns group. To add a row below the cell, click Insert Below in the Rows and Columns group.
The insertRow() method creates an empty <tr> element and adds it to a table. The insertRow() method inserts the new row(s) at the specified index in the table. Note: A <tr> element must contain one or more <th> or <td> elements. Tip: Use the deleteRow() method to remove a row.
Insert new row(s) at the beginning of a table. The insertRow() method inserts a new row at the specified index in a table, in this example, the first position (the beginning) of a table with id="myTable". Then we use the insertCell() method to add cells in the new row.
insertCell() method inserts a new cell ( <td> ) into a table row ( <tr> ) and returns a reference to the cell. Note: insertCell() inserts the cell directly into the row. The cell does not need to be appended separately with Node. appendChild() as would be the case if Document.
insertRow
would be the much better. It is supported by grade A browsers and it's less verbose and a cleaner API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With