How do I run javascript examples from sites like stackoverflow?
<p>What needs to be added inorder to run an example like what is found on here: <a href="http://stackoverflow.com/questions/3103962/converting-html-string-into-dom-elements">Converting HTML string into DOM elements?</a> in a basic HTML document?</p>

<p>Specifically I'm referring to the code:</p>

<pre><code>var xmlString = "&lt;div id='foo'&gt;&lt;a href='#'&gt;Link&lt;/a&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;"
  , parser = new DOMParser()
  , doc = parser.parseFromString(xmlString, "text/xml");
doc.firstChild // =&gt; &lt;div id="foo"&gt;...
doc.firstChild.firstChild // =&gt; &lt;a href="#"&gt;...
</code></pre>

<p>I have tried:</p>

<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;script type="text/javascript"&gt;
var xmlString = "&lt;div id='foo'&gt;&lt;a href='#'&gt;Link&lt;/a&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;"
  , parser = new DOMParser()
  , doc = parser.parseFromString(xmlString, "text/xml");
doc.firstChild;
doc.firstChild.firstChild;
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>As a beginner to javascript, a complete html copy and paste solution would be good to see how precisely it fits in.</p>
