// This is a recursive function, which traverses the // entire document and prints out a list of all the // element node names into string variable myString. // We then erase the page and display this document. // Now find document root node, then traverse the // document tree (starting from the root node), and // find out information about the tree. root = document.documentElement; // Start here contentString = traverseTree(root); // function returns a string function traverseTree(node) { if(node.nodeType == Node.ELEMENT_NODE) { // Do this if the node is a markup element var name = node.nodeName; myString = '
  • Element: '+name; if( node.hasChildNodes() ) { myString = myString + '\n