The text node will be as follows:
<p> <span>foo</span> bar </p>
<p> is a node, <span> is a node, so what is a "bar" ? β This is the text node.
Using the DOM API, you can create empty text or two adjacent text nodes:
var wrapper = document.createElement("div"); wrapper.appendChild(document.createTextNode("Part 1")); wrapper.appendChild(document.createTextNode("Part 2"));
In HTML, which will be just <div>Part 1Part2</div> , but for the DOM, these are two separate text nodes that are ... weird.
Node.normalize normalizes this to get rid of such ineffective anomalies; it will merge both text nodes into one and delete the text nodes that are completely empty.
source share