0

In my html, one extra <TR> and <TD> is added into table without close element by mistake.

<TABLE border=\"1\" summary=\"\" width=\"100%%\">
<CAPTION><EM>Statistics</EM></CAPTION><TR><TD>
<COLGROUP span=\"4\" ALIGN=\"center\"></COLGROUP>

Test it in Chrome, TBODY is added automatically, and also with close element.

enter image description here

But in IE, TBODY will be added automatically, but without close element.

enter image description here

IMO, since the HTML is incorrect, why browser will correct them by adding extra tbody?

zangw
  • 43,869
  • 19
  • 177
  • 214
  • I think the Chrome and IE DOMs you're looking at there are actually the same, they're just displayed slightly differently. – Andrew Magee Jan 13 '15 at 08:53

1 Answers1

2

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. In HTML (but not XHTML) it's allowed to leave tr and td elements without a closing tag. The table tag should have a closing tag, though.

The two browsers produce the same result, the difference is that IE is just not showing any closing tags for the elements. Once the code is parsed into elements, there are actually no opening tags and closing tags, there are only elements. The developers of Chrome just chose to show the element as an opening tag and a closing tag, presumably so that it would look more like HTML code.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • Browser behavior does not depend on DOCTYPE, but it depends on serialization mode (HTML vs. XHTML). If the document is served with an XHTML content type and therefore parsed as XHTML, `tr` is allowed as a child of `table`, so no `tbody` element is added. In HTML mode, it’s different: http://www.w3.org/TR/html5/syntax.html#element-restrictions – Jukka K. Korpela Jan 13 '15 at 11:03