HTMLTableElement: createTBody() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

The createTBody() method of the HTMLTableElement interface creates a <tbody> element, inserts it immediately after the last <tbody> element child of the given <table>, or as the last child if there is no such element, and returns it.

This method creates and inserts the element directly, without requiring separate calls to methods such as Document.createElement(), Node.insertBefore(), and Node.appendChild().

Note: Unlike HTMLTableElement.createTHead() and HTMLTableElement.createTFoot(), createTBody() always creates a new <tbody> element, even if the table already contains one or more bodies.

Syntax

js
createTBody()

Parameters

None.

Return value

An HTMLTableSectionElement (which is always a tbody).

Examples

js
const myBody = myTable.createTBody();
// Now this should be true: myBody === myTable.tBodies.item(myTable.tBodies.length - 1)

Specifications

Specification
HTML
# dom-table-createtbody-dev

Browser compatibility

See also