tags:

views:

472

answers:

3

I was playing around with some ideas using raw html and JQuery. One thing I did was to create an table element with a set of rows.

<table id="MyTable" >
    <tr>
        <td>Title</td>
    </tr>
    <tr>
        <td>1</td>
    </tr>
    <tr>
        <td>2</td>
    </tr>
    <tr>
        <td>3</td>
    </tr>
    <tr>
        <td>4</td>
    </tr>
</table>

But when I viewed the code in FireFox+Firebug, IE8 Developer Toolbar, or the Google Chrome JavaScript Debugger...all of them showed there to be a tbody element surrounding all of the tr nodes.

I'm not against this happening...but is this standard behavior?

+3  A: 

Yes, tbody is the standard element indicating the body of a table. It is not required to put it in the markup, but it will be included in the DOM as you've seen.

Matthew Flaschen
Why not thead, tfoot as well ? ;-)
Cerebrus
Looks like you can have them. I figured w3schools would have more details but this is all I found on a first pass.http://www.w3schools.com/HTMLDOM/dom_obj_table.asp
MatrixFrog
Why not thead/tfoot? Well, because they are not required to render a table where as a tbody is.
Jordan S. Jones
@Jordan: I know... but my comment was a hint to include that information in the answer to make it more complete. (See @ysth's answer).
Cerebrus
In the immortal words of Homer Simpson, "Doh!"
Jordan S. Jones
+10  A: 

http://htmlhelp.com/reference/html40/tables/tbody.html:

The TBODY element defines a group of data rows in a table. A TABLE must have one or more TBODY elements, which must follow the optional TFOOT. The TBODY end tag is always optional. The start tag is optional when the table contains only one TBODY and no THEAD or TFOOT.

So there always is a tbody there (albeit sometimes with both the start and end tabs optional and omitted), and the tools you are using are correct in showing it to you.

thead or tfoot, on the other hand, are never present unless you explicitly include them, and if you do that, the tbody(s) must be explicit too.

ysth
A: 

Interestingly if you are crawling through the dom with JavaScript the extra tbody can trip an unsuspecting person up if they don't know about it. It means that content in the table cells is nested an extra element deep!

Matthew James Taylor