davej Posted July 16, 2013 Share Posted July 16, 2013 (edited) 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 July 16, 2013 by davej Link to comment Share on other sites More sharing options...
justsomeguy Posted July 16, 2013 Share Posted July 16, 2013 It is, that's the whitespace between <body> and <p>. Link to comment Share on other sites More sharing options...
jeffman Posted July 16, 2013 Share Posted July 16, 2013 This is one of those things where jQuery can simplify your code a lot. Link to comment Share on other sites More sharing options...
davej Posted July 17, 2013 Author Share Posted July 17, 2013 So then are empty text nodes completely useless or are some text nodes important to the document structure even if they are empty? Link to comment Share on other sites More sharing options...
Ingolme Posted July 17, 2013 Share Posted July 17, 2013 Empty text nodes don't have any use in an HTML document. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now