HTMLTableElement: createTHead() method
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("HTML DOM")}}
The **createTHead()** method of the {{domxref("HTMLTableElement")}} interface creates a {{HTMLElement("thead")}} element, inserts it before the first element child of the given {{HTMLElement("table")}} that's neither a {{HTMLElement("caption")}} nor a {{HTMLElement("colgroup")}}, or as the last child if no such insertion location is found, and returns it. If the table already has a <thead> element child, this method returns the first such child without creating one.
When creation is needed, this method creates and inserts the element directly, without requiring separate calls to methods such as {{domxref("Document.createElement()")}} and {{domxref("Node.insertBefore()")}}.
Syntax
createTHead()Parameters
None.
Return value
An {{domxref("HTMLTableSectionElement")}} (which is always a thead).
Examples
const myHead = myTable.createTHead();
// Now this should be true: myHead === myTable.tHeadSpecifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- {{domxref("HTMLTableElement.createCaption()")}}
- {{domxref("HTMLTableElement.createTBody()")}}
- {{domxref("HTMLTableElement.createTFoot()")}}
- {{domxref("HTMLTableElement.deleteTHead()")}}