Append not working? (Vanilla Javascript)

var tag = document.createElement('script');
tag.src = "";
var scriptLength=document.getElementsByTagName('script').length-1;
var firstScriptTag = document.getElementsByTagName('script')[scriptLength];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

This is supposed to append a script near hte end of my page.

<script src="/uploaded/themes/build/js/main.js"></script>

These are the last few lines of my page. You see the console log there? In my Javascript? It logs-

<script src="/uploaded/themes/build/js/main.js"></script>

So it is just the append failing. Can anyone spot why?
Page - http ://hawaiip nected

not sure if it’s important, but firstScriptTag is actually the last script tag … at that time.

the insertion does appear though I don’t know if it‘s at the intended place. for me it comes before

	        new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],

Yeah I’m not going to get in depth, but it’s working now. Basically there was an issue of me calling the YT api to an element I just added an ID to in jQuery so it wasn’t running (needed delegating) but YT api does’t allow for that. Anyway it was a long process but it’s working now. It was appending (the code was working) but there were YT api issues.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.