The HTMLTableElement
interface provides special properties and methods (beyond the regular HTMLElement
object interface it also has available to it by inheritance) for manipulating the layout and presentation of tables in an HTML document.
Inherits properties from its parent, HTMLElement
.
HTMLTableElement.caption
HTMLTableCaptionElement
representing the first <caption>
that is a child of the element, or null
if none is found. When set, if the object doesn't represent a <caption>
, a DOMException
with the HierarchyRequestError
name is thrown. If a correct object is given, it is inserted in the tree as the first child of this element and the first <caption>
that is a child of this element is removed from the tree, if any.HTMLTableElement.tHead
HTMLTableSectionElement
representing the first <thead>
that is a child of the element, or null
if none is found. When set, if the object doesn't represent a <thead>
, a DOMException
with the HierarchyRequestError
name is thrown. If a correct object is given, it is inserted in the tree immediately before the first element that is neither a <caption>
, nor a <colgroup>
, or as the last child if there is no such element, and the first <thead>
that is a child of this element is removed from the tree, if any.HTMLTableElement.tFoot
HTMLTableSectionElement
representing the first <tfoot>
that is a child of the element, or null
if none is found. When set, if the object doesn't represent a <tfoot>
, a DOMException
with the HierarchyRequestError
name is thrown. If a correct object is given, it is inserted in the tree immediately before the first element that is neither a <caption>
, a <colgroup>
, nor a <thead>
, or as the last child if there is no such element, and the first <tfoot>
that is a child of this element is removed from the tree, if any.HTMLTableElement.rows
Read only
HTMLCollection
containing all the rows of the element, that is all <tr>
that are a child of the element, or a child or one of its <thead>
, <tbody>
and <tfoot>
children. The rows members of a <thead>
appear first, in tree order, and those members of a <tbody>
last, also in tree order. The HTMLCollection
is live and is automatically updated when the HTMLTableElement
changes.HTMLTableElement.tBodies
Read only
HTMLCollection
containing all the <tbody>
of the element. The HTMLCollection
is live and is automatically updated when the HTMLTableElement
changes.HTMLTableElement.sortable
Boolean
value indicating if the user agent is allowed to provide sorting mechanism for the table, if it supports such a feature. This property reflects the sortable
attribute.HTMLTableElement.align
DOMString
containing an enumerated value reflecting the align
attribute. It indicates the alignment of the element's contents with respect to the surrounding context. The possible values are "left"
, "right"
, and "center"
.HTMLTableElement.bgColor
DOMString
containing the background color of the cells. It reflects the obsolete bgcolor
attribute.HTMLTableElement.border
DOMString
containing the width in pixels of the border of the table. It reflects the obsolete border
attribute.HTMLTableElement.cellPadding
DOMString
containing the width in pixels of the horizontal and vertical sapce between cell content and cell borders. It reflects the obsolete cellpadding
attribute.HTMLTableElement.cellSpacing
DOMString
containing the width in pixels of the horizontal and vertical separation between cells. It reflects the obsolete cellspacing
attribute.HTMLTableElement.frame
DOMString
containing the type of the external borders of the table. It reflects the obsolete frame
attribute and can take one of the following values: "void"
, "above"
, "below"
, "hsides"
, "vsides"
, "lhs"
, "rhs"
, "box"
, or "border"
.HTMLTableElement.rules
DOMString
containing the type of the internal borders of the table. It reflects the obsolete rules
attribute and can take one of the following values: "none"
, "groups"
, "rows"
, "cols"
, or "all"
.HTMLTableElement.summary
DOMString
containing a description of the purpose or the structure of the table. It reflects the obsolete summary
attribute.HTMLTableElement.width
DOMString
containing the length in pixels or in percentage of the desired width fo the entire table. It reflects the obsolete width
attribute.Inherits methods from its parent, HTMLElement
.
HTMLTableElement.createTHead()
HTMLElement
representing the first <thead>
that is a child of the element. If none is found, a new one is created and inserted in the tree immediately before the first element that is neither a <caption>
, nor a <colgroup>
, or as the last child if there is no such element.HTMLTableElement.deleteTHead()
<thead>
that is a child of the element.HTMLTableElement.createTFoot()
HTMLElement
representing the first <tfoot>
that is a child of the element. If none is found, a new one is created and inserted in the tree immediately before the first element that is neither a <caption>
, a <colgroup>
, nor a <thead>
, or as the last child if there is no such element.HTMLTableElement.deleteTFoot()
<tfoot>
that is a child of the element.HTMLTableElement.createCaption()
HTMLElement
representing the first <caption>
that is a child of the element. If none is found, a new one is created and inserted in the tree as the first child of the <table>
element.HTMLTableElement.deleteCaption()
<caption>
that is a child of the element.HTMLTableElement.insertRow()
HTMLTableRowElement
representing a new row of the table. It inserts it in the rows collection immediately before the <tr>
element at the given index
position. If necessary a <tbody>
is created. If the index
is -1
, the new row is appended to the collection. If the index
is smaller than -1
or greater than the number of rows in the collection, a DOMException
with the value IndexSizeError
is raised.HTMLTableElement.deleteRow()
index
given in parameter. If the index
value is -1
the last row is removed; if it smaller than -1
or greater than the amount of rows in the collection, a DOMException
with the value IndexSizeError
is raised.HTMLTableElement.stopSorting()
sortable
attribute to all <th>
elements of the table.Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'HTMLTableElement' in that specification. | Living Standard | |
HTML5 The definition of 'HTMLTableElement' in that specification. | Recommendation | Added the createTBody() method. |
Document Object Model (DOM) Level 2 HTML Specification The definition of 'HTMLTableElement' in that specification. | Obsolete | Defined when caption , tHead , tFoot , insertRow() , and deleteRow() raise exceptions. |
Document Object Model (DOM) Level 1 Specification The definition of 'HTMLTableElement' in that specification. | Obsolete | Initial definition. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | Yes | Yes | 1 | Yes | Yes | Yes |
align
|
Yes | Yes | Yes | Yes | Yes | Yes |
bgColor
|
Yes | Yes | Yes | Yes | Yes | Yes |
border
|
Yes | Yes | Yes | Yes | Yes | Yes |
caption |
Yes | Yes | Yes | Yes | Yes | Yes |
cellPadding
|
Yes | Yes | Yes | Yes | Yes | Yes |
cellSpacing
|
Yes | Yes | Yes | Yes | Yes | Yes |
createCaption |
Yes | Yes | Yes | Yes | Yes | Yes |
createTBody |
Yes | Yes | 25 | Yes | Yes | Yes |
createTFoot |
Yes | Yes | Yes | Yes | Yes | Yes |
createTHead |
Yes | Yes | Yes | Yes | Yes | Yes |
deleteCaption |
Yes | Yes | Yes | Yes | Yes | Yes |
deleteRow |
Yes | Yes | Yes | Yes | Yes | Yes |
deleteTFoot |
Yes | Yes | Yes | Yes | Yes | Yes |
deleteTHead |
Yes | Yes | Yes | Yes | Yes | Yes |
frame
|
Yes | Yes | Yes | Yes | Yes | Yes |
insertRow |
4 | Yes | 3
|
5.5 | 10 | 4 |
rows |
Yes | Yes | Yes | Yes | Yes | Yes |
rules
|
Yes | Yes | Yes | Yes | Yes | Yes |
sortable
|
No | No | No | No | No | No |
stopSorting
|
No | No | No | No | No | No |
summary
|
Yes | Yes | Yes | Yes | Yes | Yes |
tBodies |
Yes | Yes | Yes | Yes | Yes | Yes |
tFoot |
Yes | Yes | 1 | Yes | Yes | Yes |
tHead |
Yes | Yes | 1 | Yes | Yes | Yes |
width
|
Yes | Yes | Yes | Yes | Yes | Yes |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | ? | Yes | 4 | Yes | Yes | ? |
align
|
Yes | ? | Yes | Yes | Yes | Yes | ? |
bgColor
|
Yes | ? | Yes | Yes | Yes | Yes | ? |
border
|
Yes | ? | Yes | Yes | Yes | Yes | ? |
caption |
Yes | ? | Yes | Yes | Yes | Yes | ? |
cellPadding
|
Yes | ? | Yes | Yes | Yes | Yes | ? |
cellSpacing
|
Yes | ? | Yes | Yes | Yes | Yes | ? |
createCaption |
Yes | ? | Yes | Yes | Yes | Yes | ? |
createTBody |
Yes | ? | Yes | 25 | Yes | Yes | ? |
createTFoot |
Yes | ? | Yes | Yes | Yes | Yes | ? |
createTHead |
Yes | ? | Yes | Yes | Yes | Yes | ? |
deleteCaption |
Yes | ? | Yes | Yes | Yes | Yes | ? |
deleteRow |
Yes | ? | Yes | Yes | Yes | Yes | ? |
deleteTFoot |
Yes | ? | Yes | Yes | Yes | Yes | ? |
deleteTHead |
Yes | ? | Yes | Yes | Yes | Yes | ? |
frame
|
Yes | ? | Yes | Yes | Yes | Yes | ? |
insertRow |
Yes | ? | Yes | 4
|
Yes | Yes | ? |
rows |
Yes | ? | Yes | Yes | Yes | Yes | ? |
rules
|
Yes | ? | Yes | Yes | Yes | Yes | ? |
sortable
|
No | ? | No | No | No | No | ? |
stopSorting
|
No | ? | No | No | No | No | ? |
summary
|
Yes | ? | Yes | Yes | Yes | Yes | ? |
tBodies |
Yes | ? | Yes | Yes | Yes | Yes | ? |
tFoot |
Yes | ? | Yes | 4 | Yes | Yes | ? |
tHead |
Yes | ? | Yes | 4 | Yes | Yes | ? |
width
|
Yes | ? | Yes | Yes | Yes | Yes | ? |
<table>
.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement