<html>
<head>
<title>createTextNode example</title>

<script type="text/javascript">
var i=0;
function addTextNode()
{
var newtext = document.createTextNode(" Some text added dynamically. "+(++i));
var para = document.getElementById("p1");
para.appendChild(newtext);
}
function getText(n) {
// Repeated string concatenation can be inefficient, so we collect
// the value of all text nodes into an array, and then concatenate
// the elements of that array all at once.
var strings = [];
getStrings(n, strings);
//return strings.join("");

// This recursive function finds all text nodes and appends
// their text to an array.
function getStrings(n, strings) {
if (n.nodeType == 3 /* Node.TEXT_NODE */)
strings.push(n.data);
else if (n.nodeType == 1 /* Node.ELEMENT_NODE */) {
// Note iteration with firstChild/nextSibling
for(var m = n.firstChild; m != null; m = m.nextSibling) {
getStrings(m, strings);
}
}
}
alert(strings);
}
</script>
</head>

<body >
<div style="border: 1px solid red">
<p id="p1">First line of paragraph.<br /></p>
</div><br />

<button onclick="addTextNode();">add another textNode.</button>
<button onclick="getText(document);">GetText</button>
</body>
</html>
------------------------------------------------
getText(document)work,but the strings can't get anything.The alert(strings) is null . why??