This article describes how to use DOM to control tables in basic DOM tutorials. If you want to use DOM to control tables, you can refer to the css control in the following table.
The insertRow () and insertCell () methods are commonly used to add tables.
Row is calculated from scratch, for example:
The Code is as follows:
Var oTr = document. getElementById ("member"). insertRow (2)
Adds a new row to the second row.
The Code is as follows:
Var aText = new Array ();
AText [0] = document. createTextNode ("fresheggs ");
AText [1] = document. createTextNode ("W610 ");
AText [2] = document. createTextNode ("Nov 5th ");
AText [3] = document. createTextNode ("Scorpio ");
AText [4] = document. createTextNode ("1038818 ");
For (var I = 0; ivar oTd = oTr. insertCell (I );
OTd. appendChild (aText [I]);
}
The oTr variable inserts a new row into the table, and insertCell inserts new data into the row. createTextNode is used to create a new text node, and oTd is the new cell in appendChild.
1. Insert a row (Add Table dynamically)
The Code is as follows: