Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
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...

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

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.

about 4 years ago · Santiago Gelvez Report

0

as say in the doc https://developer.mozilla.org/fr/docs/Web/API/Node/childNodes

childNodes includes all child nodes, including non-element nodes like text and comment.

to get only child node element you have to use element.children

var html = document.querySelector('html');

console.log(html.children[0]);
console.log(html.children[1]);
<!DOCTYPE html>
<html>

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

</html>

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!