Re: HTML 5 parser creating multiple body elements

On Thu, Jul 16, 2009 at 2:41 PM, Geoffrey Sneddon wrote:
> Given the following:
>
> <!doctype html>
> <script>
> document.documentElement.innerHTML = "<body bgcolor=green>";
> </script>
> <body bgcolor=red>
>
> The HTML 5 parser creates:
>
> doctype
> html
>        head
>        body@bgcolor='green'
>        body@bgcolor='red'
>
> It would be desirable not to create multiple body elements.
[...]
> None of these options seem very nice (HTML5 because it results in multiple
> body elements; Firefox/Chromium as they result in a text node child of the
> HTML element; Opera because it results in a P element child of the HTML
> element; IE because it disallows innerHTML). As IE throws when trying to set
> innerHTML on the HTML element (which, AFAIK, is the only case in which this
> can occur), I find it doubtful any sites depend on any specific behaviour,
> though it seems nicest to avoid having multiple body elements, and treating
> it closer to two body elements in the token stream.

How about changing step 2 in setting innerHTML to "If the node's
document has an active parser"? (instead of "If the attribute is being
set on a Document node, and that document has an active parser")
It wouldn't match any browser but as you said, given that IE throws,
it is "doubtful any sites depend on any specific behaviour".

I believe there are similar issues with insertAdjacentHTML, and
probably even after the parser has stopped (as soon as there is a
<body>, even when using outerHTML e.g. on <head>).

-- 
Thomas Broyer

Received on Thursday, 16 July 2009 14:04:05 UTC