Possible Duplicate:
Executing <script> elements inserted with .innerHTML
Dynamically Inserting <script> tags into HTML on Page Load
What I mean is that if I do .innerHTML write that contains
<script type="text/javascript" src="source.js"></script>
or
<script type="text/javascript"> // embedded code here </script>
The embedded code does not run and neither does the linked to code. It is “dead”.
Is there a way to manually trigger it?
you need to add the javascript to the head tag,
i.e
(this is a quite common thing, but i copied the code from here: http://www.hunlock.com/blogs/Howto_Dynamically_Insert_Javascript_And_CSS )
on a side note:
if you use jQuery you will be tempted to write the following:
note that this doesn’t work because the javascript parser will see the first
</script>and stop parsing right there.