I have created a JavaScript function which will return data containing 2 URL’s. And I would like to insert these into the HTML code.
e.g. the return URL values are
JavsScript file
http://www.domain.com/javascript.js
CSS file
http://www.domain.com/buttons.css
I need to insert these into the code as:
<link rel="stylesheet" type="text/css" href="return URL value" />
<script type="text/javascript" src="return URL value"></script>
How can I do that?
Thanks
You can load external css (and also js) files dynamically using javascript. Just create the appropriate
<link>element using javascript.At the moment, we have just created element
And we have stored it in the variable
var link. It is not over, the<link>is not part of theDOMyet.We need to append it
And it is done.
In the very similar way, you can dynamically add external javascript resource. Just use
<script>tag instead of<link>tag.