Coleção de Corpos de Tabela
Exemplo
Descubra quantos elementos <tbody> existem em uma tabela:
var x = document.getElementById("myTable").tBodies.length;
O resultado de x será:
2
Mais exemplos de "Experimente você mesmo" abaixo.
Definição e uso
A coleção tBodies retorna uma coleção de todos os elementos <tbody> em uma tabela.
Observação: os elementos da coleção são classificados conforme aparecem no código-fonte.
Suporte ao navegador
Collection | |||||
---|---|---|---|---|---|
tBodies | Yes | Yes | Yes | Yes | Yes |
Sintaxe
tableObject.tBodies
Propriedades
Property | Description |
---|---|
length | Returns the number of <tbody> elements in the collection. Note: This property is read-only |
Métodos
Method | Description |
---|---|
[index] | Returns the <tbody> element from the collection with the specified index (starts at 0). Note: Returns null if the index number is out of range |
item(index) | Returns the <tbody> element from the collection with the specified index (starts at 0). Note: Returns null if the index number is out of range |
namedItem(id) | Returns the <tbody> element from the collection with the specified id. Note: Returns null if the id does not exist |
Detalhes técnicos
Versão DOM: | Objeto de documento de nível 2 principal |
---|---|
Valor de retorno: | Um objeto HTMLCollection, representando todos os elementos <tbody> no elemento <table>. Os elementos da coleção são classificados conforme aparecem no código-fonte |
Mais exemplos
Exemplo
[ índice ]
Alerte o innerHTML do primeiro elemento <tbody> (índice 0) na tabela:
alert(document.getElementById("myTable").tBodies[0].innerHTML;
Exemplo
item ( índice )
Alerte o innerHTML do primeiro elemento <tbody> (índice 0) na tabela:
alert(document.getElementById("myTable").tBodies.item(0).innerHTML);
Exemplo
nomeadoItem( id )
Alerte o innerHTML do elemento <tbody> com id="myTBody" na tabela:
alert(document.getElementById("myTable").tBodies.namedItem("myTBody").innerHTML);
Páginas relacionadas
Referência HTML: tag HTML <tbody>
❮ Objeto de Tabela