Executing <script> elements inserted with .innerHTML
Posted
by phidah
on Stack Overflow
See other posts from Stack Overflow
or by phidah
Published on 2010-04-07T11:48:39Z
Indexed on
2010/04/07
11:53 UTC
Read the original article
Hit count: 327
I've got a script that inserts some content into an element using innerHTML
.
The content could for example be:
<script type="text/javascript">alert('test');</script>
<strong>test</strong>
Problem is that the code inside the <script>
tag doesn't get executed.
I googled it a bit but there were no apparent solutions. If I inserted the content using jQuery $(element).append(content);
the script parts got eval
'd before being injected into the DOM.
Has anyone got a snippet of code that executes all the <script>
elements? The jQuery code was a bit complex so I couldn't really figure out how it was done.
© Stack Overflow or respective owner