What needs to be added inorder to run an example like what is found on here: Converting HTML string into DOM elements? in a basic HTML document?
Specifically I'm referring to the code:
var xmlString = "<div id='foo'><a href='#'>Link</a><span></span></div>"
, parser = new DOMParser()
, doc = parser.parseFromString(xmlString, "text/xml");
doc.firstChild // => <div id="foo">...
doc.firstChild.firstChild // => <a href="#">...
I have tried:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<script type="text/javascript">
var xmlString = "<div id='foo'><a href='#'>Link</a><span></span></div>"
, parser = new DOMParser()
, doc = parser.parseFromString(xmlString, "text/xml");
doc.firstChild;
doc.firstChild.firstChild;
</script>
</body>
</html>
As a beginner to javascript, a complete html copy and paste solution would be good to see how precisely it fits in.