X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Table tBodies Collection

Table Object Reference Table Object

Example

Show the number of <tbody> elements in a table:

var x = document.getElementById("myTable").tBodies.length;
document.getElementById("demo").innerHTML=x;

The result of x will be:

2

Try it yourself »


Definition and Usage

The tBodies collection returns a collection of all <tbody> elements in a table.

Note: The elements in the collection are sorted as they appear in the source code.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The tBodies collection is supported in all major browsers.


Syntax

tableObject.tBodies

Properties

Property Description
length Returns the number of <tbody> elements in the collection

Methods

Method Description
[name_or_index] A string or integer that specifies the element to return (index starts at 0)
item(name_or_index) Returns the element from the collection with the specified index/name/id
namedItem(name_or_id) Returns the element from the collection with the specified name (name or id attribute)


More Examples

Example

[name_or_index]

Alert the innerHTML of the first <tbody> element (index 0) in the table:

alert(document.getElementById("myTable").tBodies[0].innerHTML;

Try it yourself »

Example

item(name_or_index)

Alert the innerHTML of the first <tbody> element (index 0) in the table:

alert(document.getElementById("myTable").tBodies.item(0).innerHTML);

Try it yourself »

Example

namedItem(name_or_id)

Alert the innerHTML of the <tbody> element with id="myTBody" in the table:

alert(document.getElementById("myTable").tBodies.namedItem("myTBody").innerHTML);

Try it yourself »


Related Pages

HTML reference: HTML <tbody> tag


Table Object Reference Table Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook