function createNodeFromText(text, nodeToReturn)\n{\n\tvar container = document.createElement("span");\n\tcontainer.innerHTML = text;\n\t\n\tif (!nodeToReturn)\n\t{\n\t\treturn container.firstChild;\n\t}\n\telse\n\t{\n\t\treturn container.getElementsByTagName(nodeToReturn.toUpperCase()).item(0);\n\t}\n}
'nodeToReturn' allows you to select something from within the created DOM:
createNodeFromText("<table><tr><td>1</td><td>2</td></tr></table>", "tr")
would return the TR node from the created node. Mainly I have to do this because you can't create just a TR with innerHTML.Are there any better ways to create DOM from arbitrary text?