All nodes have the property nodeType
. Its value
is numeric: 1
for elements, 3
for text
nodes, 8
for comments. The remaining values are
currently either little used or outdated.
Given a div:
<div id="elem">txt<b>tag</b><!--com-->txt<b>tag</b><!--com--></div>
Loop through all the nodes of this div and output only the element nodes and text nodes to the console.