规范文件:DOM文本节点

问题描述:

我正在阅读文件关于HTML5从我链接的几行下面,显示了示例HTML代码示例DOM树。为什么直接在< head> 元素之前没有文本节点?为什么 DOCTYPE < html> 节点之间没有文本节点?错误或功能?

I am reading a document about HTML5. A few lines down from where I linked, a sample DOM tree is displayed for the sample HTML code given. Why is there no text node directly before the <head> element? Why is there no text node between the DOCTYPE and <html> nodes? Error or feature?

功能。主要原因是,鉴于标记

Feature. The main reason is that, given the markup

<!DOCTYPE html>
<html>
 <head>
  <title>Sample page</title>
...,

有些人希望

document.documentElement.firstChild

返回元素。但是,如果包含文本节点,那就是要返回的节点。

to return the head element. However, if the text node were included, that is the node that would be returned.

(另请注意,之间的新行; / body> < / html> 最终在正文元素中。 )

(Note, also, that the new line between </body> and </html> ends up in the body element.)