Jump to content

Walking the DOM Tree


davej

Recommended Posts

I am seeing a lot of empty text nodes. I am getting the impression that white space and carriage-returns in the document create text-nodes. Is this true?

 

http://www.w3schools.com/jsref/prop_node_firstchild.asp

 

If I modify the TryIt code... it says the first-child of the <body> is an empty text node...

<!DOCTYPE html><html><body><p id="demo">Click the button get the node name of the document's first child node</p><button onclick="myFunction()">Try it</button><script>function myFunction(){var x=document.getElementById("demo");  x.innerHTML = document.body.firstChild.nodeType;x.innerHTML += '['+ document.body.firstChild.nodeValue +']';}</script></body></html>
Edited by davej
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...