Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

324
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda