Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

313
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda