Reputation: 28154
In JavaScript, are rows and cells dynamic collections?
For example:
var myRows=myTable.rows;
var newRow=myTable.insertRow();
Will newRow automatically become part of myRows?
Sorry if it seems like a basic question, but I couldn't find any reference with a clear answer.
Upvotes: 1
Views: 91
Reputation: 154908
table.rows
is* an HTMLCollection
which is live.
An
HTMLCollection
is a list of nodes. An individual node may be accessed by either ordinal index or the node'sname
orid
attributes.Note: Collections in the HTML DOM are assumed to be live meaning that they are automatically updated when the underlying document is changed.
* As specified here:
Object
HTMLTableElement
...
rows
This property is of type
HTMLCollection
.
Upvotes: 2
Reputation: 39882
Just try it and see:
<table>
<tr><td></td></tr>
</table>
<script>
var myTable = document.getElementsByTagName('table')[0];
var myRows=myTable.rows;
alert(myRows.length); //alerts 1
var newRow=myTable.insertRow();
alert(myRows.length); //alerts 2
</script>
So yes.
Upvotes: 1