JavaScript DOM traversal order -
i wrote following page demonstrate dom traversing:
<html> <head> <title>dom traversal</title> </head> <body> <div> <p>sample paragraph</p> </div> <h1>sample h1</h1> <script> // traversing dom tree "use strict"; var node = document.body; document.addeventlistener("domcontentloaded", function (event) { while(node) { console.log(node); node = node.firstchild; } }, false); </script> </body> </html>
according me, output should body -> div -> p body -> #text. can explain #text , why i'm not getting desired order?
those "empty-text" nodes, blogged them here:
https://weblogs.asp.net/stevewellens/secret-covert-hush-hush-white-space-in-the-dom-exposed
they explained here: http://www.w3.org/dom/faq.html#emptytext
Comments
Post a Comment