Derse geri dön
Bu materyal sadece عربي, English, Español, Français, Italiano, 日本語, 한국어, Русский, Українська, 简体中文 dillerinde mevcuttur. Lütfen Türkçe diline çevirmek için bize yardım edin.

What's in the nodeType?

önem: 5

What does the script show?

<html>

<body>
  <script>
    alert(document.body.lastChild.nodeType);
  </script>
</body>

</html>

There’s a catch here.

At the time of <script> execution the last DOM node is exactly <script>, because the browser did not process the rest of the page yet.

So the result is 1 (element node).

<html>

<body>
  <script>
    alert(document.body.lastChild.nodeType);
  </script>
</body>

</html>