dynamic - JavaScript load script dynamically inside a DIV -
i have created div dynamically , want contain javascript link, output on it. javascript link source absolute. obviously, doesn't work:
var div = document.createelement('div'); div.id = 'mydiv'; div.innerhtml = "<script type='text/javascript' " + "src='http://mydomain.com/myscript.js'></script>"; document.body.appendchild(div); so tried one
var script = document.createelement('script') script.setattribute('type', 'text/javascript'); script.setattribute('src', 'http://mydomain.com/myscript.js'); var div = document.createelement('div'); div.id = 'mydiv'; div.appendchild(script); document.body.appendchild(div); in script file have simple alert('testing...'); code. problem doesn't work. script inclusion typed inside div (i see when inspect div in chrome), doesn't work. don't see 'testing...' message. missing or doing wrong? thanks!
the way understand it, code not wait till dom ready.
it advised use jquery's ready ensure script passed runs after dom ready
hope helps
Comments
Post a Comment