add javascripts and css files dynamicly to html using javascript -
i building javascript widget , need add widget css , js files dynamicly client page.
i doing now:
var css = document.createelement('link'); css.setattribute('rel', 'stylesheet'); css.setattribute('href', 'css path'); document.getelementbyid('test').appendchild(css); alert(document.getelementbyid('test').innerhtml);
but not add element dom. alert shows correctly.
what missing?
edit1:
here updated code: (note test page).
<html> <head> </head> <body> <div id="test"> test </div> <script type="text/javascript"> var css = document.createelement('link'); css.setattribute('rel', 'stylesheet'); css.setattribute("type", "text/css"); css.setattribute('href', 'path'); var header = document.getelementsbytagname("head")[0]; header.appendchild(css); alert(header.innerhtml); </script> </body> </html>
header.innerhtml appears correct nothing added page.
have tried append css <head> section ?
var css = document.createelement('link'); css.setattribute('rel', 'stylesheet'); css.setattribute('href', 'css path'); document.getelementsbytagname('head')[0].appendchild(css);
Comments
Post a Comment