0

This is a simple HTML and JS code, but why scripts tag after body tag, count as childNodes of body!?

I am trying it in FF 35

<!DOCTYPE HTML>
<html>
    <head>
    </head>
    <body id='body'>This is only text node</body>
</html>

<script>
    var b;
</script>
<script>
    var b = document.getElementById('body');
    console.log(b.childNodes.item(3).textContent);
</script>
Amir Shabani
  • 690
  • 2
  • 14
  • 36

1 Answers1

0

as others have pointed out the script tags must be inside the HTML tags otherwise browsers will try and fix it for you with bad consequences.

JSB
  • 221
  • 2
  • 13