0

Why doesn't text node(spaces) come if we try to get firstChild node of HTMLhtmlElement?

In the attached image, there are some spaces between <html> and <head> tag and ideally firstChild Node object of html node should be text node instead of head node.

Is there any know bug?

I tried it in Chrome.

Note: spaces b/w head and body is properly reflected in dom traversal api call, for example nextSibling of head is Text node in this example.

enter image description here

4

1 回答 1

2

Because the content model of the html element doesn't allow text, so any whitespace there can be completely ignored by the parser.

Contrast this with the content model of (say) the body element, which is Flow Content, which lists (amongst other things) text. Although I expect you'll find that leading whitespace after <body> and before another tag (say, <p>) will also be left out. I expect that's covered by one of the dozens of parsing states described in §8.2.

于 2013-03-30T14:45:26.723 回答