MDN self-hosted library · e01.org

HTMLTableElement: createTBody() method

HTML DOM

HTML DOM

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

createTBody()

Parameters

None.

Return value

An HTMLTableSectionElement (which is always a tbody).

Examples

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

Specifications

Browser compatibility

See also

  • HTMLTableElement.createCaption()
  • HTMLTableElement.createTFoot()
  • HTMLTableElement.createTHead()