When I try to execute this code :
index.html :
<div id="mydiv">test</div>
<script type="text/javascript">
$('#mydiv').html('<script type="text/javascript" id="myscript" src="test.js"><\/script>');
</script>
test.js :
alert(document.getElementById('myscript').src);
I have this error :
document.getElementById("myscript") is null
I would like to resolve it, knowing that "'<script type="text/javascript" id="myscript" src="test.js"></script>'" is obtained by an ajax call, mixed with others contents, but I simplified the code for the example.
you should use
document.CreateElementanddocument.body.appendChildto make your script tag available to getElementById . you can check this questionin your case it could be