Jump to content

#text elements with nodeValue = "\n"


kilp-web@sbcglobal.net

Recommended Posts

I have been experimenting with the following code:

<html><head><title>List the Tags</title><script type="text/javascript">function listTags(n, i) {        ++i;    // Loop through all the children of n    for(var m = n.firstChild; m !== null; m = m.nextSibling) {        alert(i);        if (m.nodeType === 3)  { // Text Node            if (m.nodeValue === "\n") {                alert(m.parentNode.nodeName + "    " + m.nodeName + "   " + m.firstChild + "\n" + "    nodeValue is 'linefeed'");            } else {                alert(m.parentNode.nodeName + "    " + m.nodeName + "   " + m.firstChild + "\n" + "    nodeValue is: " + m.nodeValue);            }        } else {            alert(m.parentNode.nodeName + "    " + m.nodeName + "    " + m.firstChild.nodeName);        }        listTags(m, i);    }}</script></head><body onload="listTags(document,0);"><button onclick="bounce.start()">Start</button><button onclick="bounce.stop()">Stop</button></body></html>

When I run this it shows that there are a lot of unexpected (by me at least) #text nodes whose nodeValue is "\n".Is there a bug in my code or are these real? If they are real, what purpose do they serve?I have run this on both Safari and Firefox with the same results.Thanks,Jerry

Link to comment
Share on other sites

That symbol indicates a new line. You are examining all the lines in your document. Everywhere a new line begins, there must be a text node with a new line character. Sometimes it is the only character. Sometimes it may be combined with tabs or spaces.Their purpose is to make your page look readable. Those are the places where you hit the return key.

Link to comment
Share on other sites

That symbol indicates a new line. You are examining all the lines in your document. Everywhere a new line begins, there must be a text node with a new line character. Sometimes it is the only character. Sometimes it may be combined with tabs or spaces.Their purpose is to make your page look readable. Those are the places where you hit the return key.
Thanks for the help. Once again, you have provided a clear and thoughtful response.Jerry
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...