I wonder why this code works and shows up in the source and the other code does not?
Code showing up:
function test() {
var scriptElement2 = document.createElement("script");
scriptElement2.id = 'test';
var head = document.getElementsByTagName("head")[0] || document.documentElement;
head.appendChild(scriptElement2);
}
test();
Code not showing up:
function test() {
var scriptElement2 = document.createElement("script");
scriptElement2.id = 'test';
scriptElement2.src = 'http://test.com/ja.js';
scriptElement2.type = "application/javascript";
var head = document.getElementsByTagName("head")[0] || document.documentElement;
head.appendChild(scriptElement2);
}
test();
I only added the two lines :
scriptElement2.src = 'http://test.com/ja.js';
scriptElement2.type = "application/javascript";
Now the code does not work anymore, the does not show up in the HTML sourcecode. And yes I tried it with an valid src.