var newScript = document.createElement("script"); var inlineScript = document.createTextNode("alert('Hello World!');"); newScript.appendChild(inlineScript); target.appendChild(newScript);