<p>I'm working on a web page where I'm making an AJAX call that returns a chunk of HTML like: </p>

<pre><code>&lt;div&gt;
  &lt;!-- some html --&gt;
  &lt;script type="text/javascript"&gt;
    /** some javascript */
  &lt;/script&gt;
&lt;/div&gt;
</code></pre>

<p>I'm inserting the whole thing into the DOM, but the JavaScript isn't being run.  Is there a way to run it?  </p>

<p>Some details: I can't control what's in the script block (so I can't change it to a function that could be called), I just need the whole block to be executed.  I can't call eval on the response because the JavaScript is within a larger block of HTML.  I could do some kind of regex to separate out the JavaScript and then call eval on it, but that's pretty yucky.  Anyone know a better way?</p>

You don't have to use regex if you are using the response to fill a div or something. You can use getElementsByTagName.
```
```
div.innerHTML = response;
var scripts = div.getElementsByTagName('script');
for (var ix = 0; ix < scripts.length; ix++) {
    eval(scripts[ix].text);
}
```
```