<script>
tags written to innerHTML
are not executed at write-time. You can do element.getElementsByTagName('script')
to try to get hold of them and execute their scripts manually, but it's very ugly and not reliable.
There are tedious browser differences to do with what happens to a <script>
element written to innerHTML
which is then (directly or via an ancestor) re-inserted into the document. You want to avoid this sort of thing: just don't write <script>
s to innerHTML
at all.
Then you also don't have to worry about executing scripts twice, which is something you never want to do with library scripts. You don't want to end up with two copies of a function/class that look the same but don't compare equal, and which hold hooks onto the page that don't play well with each other. Dynamically-inserted library scripts are a recipe for confusing failure.
Much better to include your scripts statically, and bind them to page elements manually after writing new elements to the page. If you really need to you can have your AJAX calls grab a JSON object containing both the new HTML to add and a stringful of script to execute.