Search code examples
javascriptdomnodes

DOM Node ,, Why html.childNode[2] is body?


<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>document</title>
</head>
<body></body>
</html>

why html.childNode[2] is BODY ??

I think html.childNode[0] is HEAD. and html.childNode[1] is BODY.

But, html.childNode[1] is #text. why this happens?? I can't see any text...


Solution

  • 0 - is the head. 1 - is a text node - that linefeed between closing </head> and opening <body>. If you remove the line break, body will have the index 1.