function showDOM() { var win = open('','','width=500, height=500'); win.document.write(''); showChildNodes(document.documentElement, win.document); win.document.write(''); } function showChildNodes(node, doc) { if(node.nodeType == 3){ doc.write(node.nodeValue); } else if (node.nodeType == 1) { doc.write('
'); doc.write(node.nodeName); for(var i = 0; i < node.childNodes.length; i++){ showChildNodes(node.childNodes[i], doc); } doc.write('
'); } }