トラバースのためにいくつかの簡単なJSテストを実行していますが、なぜdocumentElementが1つのnullオブジェクトで構成されているのか疑問に思いました。
<html>
<head>
<title>My document</title>
</head>
<body>
<h1>Some header</h1>
<p id="pID">Some paragraph</p>
<p name="pNAME">Another paragraph/p>
</body>
</html>
<script type="text/javascript">
var rootElement = document.documentElement;
var childNodes = rootElement.childNodes;
for (var i = 0; i < childNodes.length; i++) {
document.write(childNodes[i].localName);
document.write("<br>");
}
</script>
を返しますhead, null, body
。しかし、なぜ3childNodes
が含まれているのrootElement
ですか?