Colección Table tBodies
Ejemplo
Averigüe cuántos elementos <tbody> hay en una tabla:
var x = document.getElementById("myTable").tBodies.length;
El resultado de x será:
2
Más ejemplos de "Pruébelo usted mismo" a continuación.
Definición y uso
La colección tBodies devuelve una colección de todos los elementos <tbody> de una tabla.
Nota: Los elementos de la colección se ordenan tal como aparecen en el código fuente.
Compatibilidad con navegador
Collection | |||||
---|---|---|---|---|---|
tBodies | Yes | Yes | Yes | Yes | Yes |
Sintaxis
tableObject.tBodies
Propiedades
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 |
Detalles técnicos
Versión DOM: | Objeto de documento básico de nivel 2 |
---|---|
Valor devuelto: | Un objeto HTMLCollection, que representa todos los elementos <tbody> en el elemento <table>. Los elementos de la colección se ordenan tal como aparecen en el código fuente. |
Más ejemplos
Ejemplo
[ índice ]
Alerta al HTML interno del primer elemento <tbody> (índice 0) en la tabla:
alert(document.getElementById("myTable").tBodies[0].innerHTML;
Ejemplo
artículo ( índice )
Alerta al HTML interno del primer elemento <tbody> (índice 0) en la tabla:
alert(document.getElementById("myTable").tBodies.item(0).innerHTML);
Ejemplo
elemento con nombre ( id )
Alerta al HTML interno del elemento <tbody> con id="myTBody" en la tabla:
alert(document.getElementById("myTable").tBodies.namedItem("myTBody").innerHTML);
páginas relacionadas
Referencia HTML: etiqueta HTML <tbody>
❮ Objeto de tabla