Example function:
function myFunction() {
alert("Test");
}
myFunction();
This will run fine when called in a normal HTML webpage. But if this is part of the innerHTML content that is returned from an AJAX call, the function call myFunction();
won't work.
For example, if the content of a div TestDiv
is changed via AJAX, and the innerHTML contains the following:
<span>AJAX Result</span>
<script language="JavaScript">myFunction();</script>
This code will not work when the AJAX request is complete. How can this be fixed?