Tabelrijen verzameling
Definitie en gebruik
rijen
De verzameling retourneert een verzameling van alle <tr>-elementen in de tabel.
Note:Elements in the collection are sorted in the order they appear in the source code.
Tip:Use insertRow() Methode Maak een nieuwe rij (<tr>).
Tip:Use deleteRow() Methode Delete row.
Tip:Use insertCell() method Create a new cell (<td>).
Tip:Use deleteCell() method Delete cell.
Tip:Use cells collection Returns a collection of all <td> or <th> elements in the table.
See also:
HTML Reference Manual:HTML <tr> tag
JavaScript Reference Manual:HTML DOM TableRow object
Instance
Example 1
Find out how many rows are in the table:
var x = document.getElementById("myTable").rows.length;
The result of x will be:
2
Example 2: [index]
Prompt the innerHTML of the first <tr> element (index 0) in the table:
alert(document.getElementById("myTable").rows[0].innerHTML;
Example 3: item(index)
Prompt the innerHTML of the first <tr> element (index 0) in the table:
alert(document.getElementById("myTable").rows.item(0).innerHTML);
Example 4: namedItem(id)
Prompt the innerHTML of the <tr> element with id="myRow" in the table:
alert(document.getElementById("myTable").rows.namedItem("myRow").innerHTML);
Example 5
Change the content of the first table cell:
var x = document.getElementById("myTable").rows[0].cells; x[0].innerHTML = "NEW CONTENT";
Syntax
tableObject.rows
Property
Property | Description |
---|---|
length |
Returns the number of <tr> elements in the collection. Note:This property is read-only. |
Method
Method | Description |
---|---|
[index] |
Returns the <tr> element at the specified index in the collection (starting from 0). Note:Returns null if the index is out of range. |
item(index) |
Returns the <tr> element at the specified index in the collection (starting from 0). Note:Returns null if the index is out of range. |
namedItem(id) |
Returns the <tr> element with the specified id in the collection. Note:Returns null if the id does not exist. |
Technical details
DOM version: | Core Level 2 Document Object |
---|---|
Return value: |
HTMLCollection object, representing all <tr> elements within the <table> element. Elements in the collection are sorted in the order they appear in the source code. |
Browser support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |