I viewed the html source code, there is no <tbody>
, but when viewed via firebug in the HTML tab, <tbody>
appears. Any idea why?
The browser has to correct the code in order to create a DOM hieararchy from it. The code is incorrect, but how much depends on the DOCTYPE that you are using. There is no need to specify the tbody element, it's added automatically.
Zero or more <tr> elements. The <tbody> element is not a required child element for a parent <table> element to graphically render. However, it must be present, if the parent <table> element has a <thead> , a <tfoot> or another <tbody> element as a child.
The <tbody> tag is used to group the body content in an HTML table. The <tbody> element is used in conjunction with the <thead> and <tfoot> elements to specify each part of a table (body, header, footer). Browsers can use these elements to enable scrolling of the table body independently of the header and footer.
To summarize the excellent explanations given in the answers and comments by bobince, Kieron, Alohci and others:
TBODY
element in the DOM is added by the HTML parser. Note that this weird parsing is limited to text/html documents and in XHTML the DOM corresponds closely to the source XML. table
is (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)
-- tr
s are only allowed in tbody
! The spec says that tbody
's start tag is optional, which is supposed to mean that if the HTML parser encounters tr
directly inside a table
it inserts the tbody
start tag omitted by the author.Its not firebug, but firefox which does that. This is the way tables are supposed to be written with <TBODY>
separate from meta data like <COLGROUP>
Firefox simply inserts the <TBODY>
tags when it finds them missing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With