I have the below js. which is also in this fiddle
(function () {
var test = document.createElement('script');
test.type = 'text/javascript';
test.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'www.example.com/test.js';
console.log(test);
document.getElementsByTagName('body')[0].insertAdjacentHTML("beforeEnd", test);
})();
I want to put the js at the bottom of my page just before the closing js tags.
When I view it in the console.log I get the expected result. Which is
<script type="text/javascript" src="http://www.example.com/test.js"></script>
However when I try and actually add it to my page I get [object HTMLScriptElement]
What am I missing here or is there another method I can try to acheive this?