title: Dynamically adding div element from html encoded string containing Div and Script markup
body: <p>i have python app that passes html to page as part of a json payload.   what i am trying to do in that page is to decode the html and dynamically add it to the DOM.  the html markup is for a Div element with child script elements.   this is my code, which prints out the decoded HTML fine, but does not actually execute the script:</p>
  
  <pre><code>&lt;div  id="parentDiv"&gt;
      &lt;script src="http://code.jquery.com/jquery-2.1.1.min.js"&gt;&lt;/script&gt;
      &lt;script type='text/javascript'&gt;
          var child_div = "&amp;lt;div id=&amp;#39;testDiv&amp;#39;&amp;gt;\n &amp;lt;script src=&amp;quot;http://d3js.org/d3.v3.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;\n &amp;lt;script&amp;gt;\n d3.select(&amp;quot;#testDiv&amp;quot;) \n .data([4, 8, 15, 16, 23, 42])\n .enter().append(&amp;quot;p&amp;quot;)\n .text(function(d) { return &amp;quot;I'm number &amp;quot; + d + &amp;quot;!&amp;quot;;\n });\n &amp;lt;/script&amp;gt;\n &amp;lt;/div&amp;gt;";
          decoded = $('&lt;div /&gt;').html(child_div).text();
          console.log(decoded);
          $("#parentDiv").append(decoded);
      &lt;/script&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>If however i take that html that is logged in the above code and create a page out of it, it works fine with the script executing as it should.  this is what the decoded html looks like and what i am hoping to dynamically add to the parent div:</p>
  
  <pre><code>   &lt;div  id="parentDiv"&gt;
      &lt;script src="http://code.jquery.com/jquery-2.1.1.min.js"&gt;&lt;/script&gt;
      &lt;div id='testDiv'&gt;
         &lt;script src="http://d3js.org/d3.v3.min.js"&gt;&lt;/script&gt;
         &lt;script&gt;
             d3.select("#testDiv")
            .data([4, 8, 15, 16, 23, 42])
            .enter().append("p")
            .text(function(d) { return "I'm number " + d + "!"; });
         &lt;/script&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>What am i doing wrong here?</p>