views:

71

answers:

2

Hello, I had my webpage validated for xhtml transitional till I added this table (see below). Since then it doesn't validate and says "

document type does not allow element "tfoot" here <tfoot>

The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error)."

Any ideas as what is happening? I checked for any opened and not closed tags but did not find any so I don't know what else is wrong.

<table>
<caption>
My first table, Anna
</caption>
<thead>
<tr>
<th>
June
</th>
<th>
July
</th>
<th>
August
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
 Data 1
</td>
<td>
Data 2
</td>
<td>
 Data 3
</td>
<td>
Data 4
 </td>
 </tr>
 <tr>
 <td>
   Data a
  </td>
   <td>
 Date b
</td>
<td>
Data c
</td>
<td>
Data d
</td>
</tr>
<tfoot>
<tr>
<td>
Result1
</td>
</tr>
</tfoot>
</tbody>
</table>
+1  A: 

You've got the <tfoot> at the end of the table. It should be between the <thead> and the <tbody>. It will appear at the bottom, but it's coded at the top. One of the original ideas is that as a large table loaded, the heading and footer would be visible quickly, with the rest filling in (esp. useful if the body was scrollable between them). It hasn't quite worked out like that in practice, but it does make more sense if you know that.

In the DTD it lists:

<!ELEMENT table (caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+))>

That is, optional caption, then zero-or-more col or colgroup, then optional thead, then optional tfoot, then at least one tbody or tr.

Jon Hanna
A: 

The tfoot element should be outside of the tbody element, like this:

<table>
<caption>
My first table, Anna
</caption>
<thead>
<tr>
<th>
June
</th>
<th>
July
</th>
<th>
August
</th>
</tr>
</thead>
<tfoot>
<tr>
<td>
Result1
</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>
 Data 1
</td>
<td>
Data 2
</td>
<td>
 Data 3
</td>
<td>
Data 4
 </td>
 </tr>
 <tr>
 <td>
   Data a
  </td>
   <td>
 Date b
</td>
<td>
Data c
</td>
<td>
Data d
</td>
</tr>
</tbody>

Here is a small example of the correct nesting for those who need it.

<table>
    <caption></caption>
    <thead>
        <tr>
            <th></th>
        </tr>
    </thead>
    <tfoot>
         <tr>
             <td></td>
         </tr>
    </tfoot>
    <tbody>
         <tr>
             <td></td>
         </tr>
    </tbody>
</table>
Sohnee